July 2019
Intermediate to advanced
502 pages
14h
English
The headless user-db service has no cluster IP, as follows:
$ kubectl get svc user-dbNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEuser-db ClusterIP None <none> 5432/TCP 4d
However, it does have endpoints, which are the IP addresses in the cluster of all the pods that back the service:
$ kubectl get endpoints user-dbNAME ENDPOINTS AGEuser-db 172.17.0.25:5432 4d
This is a good option; endpoints are not exposed through environment variables, such as a service with a cluster IP (<service name>_SERVICE_HOST and <service name>_SERVICE_PORT). So, for a service to find the endpoints of a headless service, they'll have to query the Kubernetes API directly. While that's possible, it adds unnecessary coupling ...