When creating a headless service in Kubernetes, it auto-generates the CNAME for each pod. I need to access this hostname somehow on pod boot. I can't seem to find it in the downward API or set in any kind of environment variable. Where can I get this value from within the pod itself, or is it even possible?
Right now running dig
on the service returns the following:
_etcd-server._tcp.etcd.databases.svc.cluster.local. 30 IN SRV 10 100 2380 3730623862383630.etcd.databases.svc.cluster.local.
At the very least I need the 3730623862383630
portion of the URL.
It sounds like you want to treat your pods as pets, not cattle. Maybe you can try to use PetSet
s and headless Service
? Then you will have the DNS entry like etcd-0.databases.svc.cluster.local
which can be used during startup.