Port representation in kubernetes port list

12/28/2018

I deployed a kubernetes loadbalancer on google cloud.

$kubectl expose deployments nginx --port 80 --type LoadBalancer
$kubectl get services
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.31.240.1    <none>        443/TCP        9m
nginx        LoadBalancer   10.31.253.32   35.188.14.5   80:30787/TCP   1m

Notice the nginx port has 80 and 30787. What does these two ports mean?

-- drdot
google-cloud-platform
kubernetes

1 Answer

12/28/2018

Notice the nginx port has 80 and 30787. What does these two ports mean?

A kubectl describe service nginx would likely be more explanatory, but the tl;dr is that 80 is the port from inside the cluster, and 30787 is the NodePort pointing to port 80 of that Service. The NodePort is required because in order for whatever load balancer is running on 35.188.14.5 to connect into the cluster, it needs a TCP/IP port that it can use, since it (hopefully!) cannot use 10.31.253.32:80 to otherwise communicate with that Service the way things inside the CNI boundary do.

-- mdaniel
Source: StackOverflow