Kubernetes service ports mapping

7/23/2019

I noticed, and I cannot explain, that some services have

NAME      TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
web       NodePort   10.104.133.249   <none>        8080:31637/TCP   12m

the PORT(S) sections looks like this8080:31637/TCP. But this service

NAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE    SELECTOR                                                         
grafana                         ClusterIP   10.109.88.206    <none>        80/TCP     84s    app=grafana,release=grafana

Only has 80/TCP. What exactly is the difference between these services? And what exactly does the port 31637 do?

-- Jeanluca Scaljeri
kubernetes
kubernetes-service

1 Answer

7/23/2019

Service abstract way to expose an application running on a set of Pods as a network service. With ClusterIP, services are reachable by pods/services in the cluster but cannot accessible from outside network whereas NodePort, exposed a service on a random port between range 30000-32767 which is basically map to port inside your cluster.

In your case web service is exposed as type NodePort and you can access it from outside on port 31637 whereas you could not able to access grafana service as it is not exposed to outside network.

Check this thread, What's the difference between ClusterIP, NodePort and LoadBalancer service types in Kubernetes? It will help to understand a concept and how it works.

-- mohan08p
Source: StackOverflow