How to find out the ip address of the nodePort

1/31/2020

I have expose my deployment to the specific nodeport, if I want to connect to this deployment in cluster, how can I find the ip address of nodeport?

-- ccd
kubernetes

1 Answer

1/31/2020

You access NodePort service with <node-ip>:<node-port>.

1. Check Node IP

To check node-ip, you can execute the following command:

$ kubectl get nodes -o wide
NAME                                                STATUS   ROLES    AGE     VERSION           INTERNAL-IP     EXTERNAL-IP     OS-IMAGE                             KERNEL-VERSION   CONTAINER-RUNTIME
gke-rafal-test-cluster-default-pool-ef8193e3-1450   Ready    <none>   6m47s   v1.13.11-gke.23   192.168.1.234   35.188.23.46    Container-Optimized OS from Google   4.14.138+        docker://18.9.7
gke-rafal-test-cluster-default-pool-ef8193e3-1bd4   Ready    <none>   6m47s   v1.13.11-gke.23   192.168.1.230   34.67.114.201   Container-Optimized OS from Google   4.14.138+        docker://18.9.7
gke-rafal-test-cluster-default-pool-ef8193e3-q3c4   Ready    <none>   6m47s   v1.13.11-gke.23   192.168.1.228   34.69.230.23    Container-Optimized OS from Google   4.14.138+        docker://18.9.7

Any of node EXTERNAL-IP will work, so you can use 35.188.23.46, 4.67.114.201, or 34.69.230.23. It doesn't matter.

If you don't see any EXTERNAL-IP, it may mean that your Kubernetes nodes do not have external IPs, so you just can't access them from outside.

If you run minikube, you can check node ip with the minikube ip command. If you run Docker Desktop Kubernetes, then node ip is localhost.

2. Check Node Port

To check node-port, you can execute the following command.

$ kubectl get svc
NAME                             TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                        AGE
my-release-hazelcast             NodePort       10.208.7.24    <none>        5701:31096/TCP                 4s

The <node-port> is 31096.

-- RafaƂ Leszko
Source: StackOverflow