Accessing or Controlling the SRV CNAME in Headless Services

10/26/2016

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.

-- Jason Waldrip
kubernetes

1 Answer

10/28/2016

It sounds like you want to treat your pods as pets, not cattle. Maybe you can try to use PetSets and headless Service? Then you will have the DNS entry like etcd-0.databases.svc.cluster.local which can be used during startup.

-- Maciej Strzelecki
Source: StackOverflow