Sri Vishnuvardhan:
Hi all. I have one doubt regarding NodePort and ClusterIP services used in K8s. What are the differences among these and when to use what? Kindly let me know.
mjv:
NodePort is upgraded version of ClusterIP.
ClusterIP can be accessed only on ClusterIP IP address,in other words from resources in the cluster
while NodePort has ClusterIP functionallity plus the assigned nodePort port on each node in the cluster
thus,you can access to the NodePort service at any node via checking localhost:NodePort
or k8s_node_ip:NodePort
you should create 2 svc with this types and then compare iptables rules for them (e.g. sudo iptables-rules | grep svc_name
)
unnivkn:
Hi @Sri Vishnuvardhan fyr: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
Sri Vishnuvardhan:
Thank you so much guys for those explanations… Understood about its differences. But, still exploring the significance of using NodePort, since ClusterIP is enough to expose the service internally with secure.
Aneek Bera:
These are different ways to expose the service. For more secured environments, ClusterIP is used as it can be exposed only by admins owing that particular cluster. For external access NodeIP may be used.
unnivkn:
Hi @Sri Vishnuvardhan nodePort allows you to access your application outside the k8s cluster, where as ClusterIP service is used to access the request with in the cluster. For more information please refer this:
https://blog.ovhcloud.com/getting-external-traffic-into-kubernetes-clusterip-nodeport-loadbalancer-and-ingress/