I created a POD and exposed it as service using following command:
kubectl run nginx --image=nginx --restart=Never --port=80 --expose
When i execute following commands i get two different IP addresses. What are the below IP addressed represents ? Which IP should be used by other services while calling my service in the cluster.
master $ kubectl get ep nginx
NAME ENDPOINTS AGE
nginx 10.40.0.1:80 11m
master $ kubectl get svc nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx ClusterIP 10.103.78.253 <none> 80/TCP 12m
The IP in the endpoints of a service is the IP of the backend pods selected by the selector of the service matching with labels on the pods..If there are more than one replica of the pod there will be more than one IP in the endpoints. The IP in ClusterIP is a virtual IP is what should be used for calling a service.The service forward(with load balancing) any request coming via the clusterIP to POD IPs present in the endpoints.
From the docs here.