Hi All, I want to deploy docker image in kubernetes and run service in nodeport, . . .

Mohit Kachhwani:
Hi All, I want to deploy docker image in kubernetes and run service in nodeport, I did it by creating manifest but how to do it using command line? Can any one help. I think it will not be difficult but I am new to kubernetes

Marko Eremija:
Find what kubectl expose and kubectl create service do

unnivkn:
hi @Mohit Kachhwani fyi: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#run

unnivkn:
k run test-nginx --image=nginx --port=80
k expose po test-nginx --port=80 --name node-port-svc --dry-run=client -o yaml > 1.yaml

–update type: NodePort
vim 1.yaml

controlplane $ cat 1.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
run: test-nginx
name: node-port-svc
spec:
type: NodePort
ports:

  • port: 80
    protocol: TCP
    targetPort: 80
    selector:
    run: test-nginx
    status:
    loadBalancer: {}
    controlplane $

k apply -f 1.yaml

k get svc,ep

controlplane $ k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17m
service/node-port-svc NodePort 10.106.190.230 <none> 80:32571/TCP 10s
controlplane $

controlplane $ k get po -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test-nginx 1/1 Running 0 4m20s 192.168.1.4 node01 <none> <none>
controlplane $

Mohit Kachhwani:
Thanks

Mohit Kachhwani:
@unnivkn How to specify specific nodeport to the nodeport service in command line?

Mohit Kachhwani:
Patching workd for me

Swapnil S:
–type=NodePort

Mohit Kachhwani:
no it was not for --type. but to specify nodePort . It is not supported by kubectl expose command

unnivkn:
Hi @Mohit Kachhwani if you like to add a specific nodePort, you have to manually edit the yaml & update it, else it will assign a random nodePort.

unnivkn:

Mohit Kachhwani:
@unnivkn kubectl patch command worked for me (updating random port with the desired one), it is no more issue. Thanks!

unnivkn: