How can I access Nginx which is deployed on Kubernetes?

11/27/2018

I have two nodes - master(10.0.0.4) and node(10.0.0.5). I run below command to start Nginx.

$ kubectl run my-web --image=nginx --port=80
$ kubectl expose deployment my-web --target-port=80 --type=NodePort

my various command output is long and is as:

https://drive.google.com/open?id=1ePI4MtshhgN83RzlFJ766bGe-gyglWQY
-- hk'
kubernetes

1 Answer

11/27/2018

Since you defined NodePort type service, you can access it using node-ip:node-port.

CC@Kmaster:~$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        8h
my-web       NodePort    10.111.139.225   <none>        80:31533/TCP   3h18m

From above we can see node port for my-web is 31533.

-- nightfury1204
Source: StackOverflow