What is the use of external IP address option in kubernetes service when the service is of type ClusterIP
When you are using service with type: ClusterIP
it has only Cluster IP and no external IP address <none>
.
ClusterIP is unique Ip given from IP pool to a service and to access pods of this service cluster IP can be used only inside a cluster.Cluster IP is default service type in kubernetes.
kubectl expose deployment nginx --port=80 --target-port=80 --type=LoadBalancer
above example will create a service with external IP and cluster IP. In case of loadbalancer,nodeport services ,the service can be accessed from other clusters through externalIP
ClusterIP is the default service type in Kubernetes which allows you to reach your service only within the cluster.
If your service type is set as LoadBalancer or NodePort, ClusterIP
is automatically created and LoadBalancer
or NodePort
service will route to this ClusterIP
IP address.
The new external IP addresses are only allocated with LoadBalancer
type.
You can also use the node's external IP addresses when you set your service as NodePort
. But in this case you will need extra firewall rules for your nodes to allow ingress traffic for your exposed node ports.
An ExternalIP
is just an endpoint through which services can be accessed from outside the cluster, so a ClusterIP
type service with an ExternalIP
can still be accessed inside the cluster using its service.namespace DNS name, but now it can also be accessed from its external endpoint, too. For instance, you could set the ExternalIP
to the IP of one of your k8s nodes, or create an ingress to your cluster on that IP.