Jason Waldrip
Jason Waldrip

Reputation: 5148

Accessing or Controlling the SRV CNAME in Headless Services

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.

Upvotes: 3

Views: 280

Answers (1)

Maciej Strzelecki
Maciej Strzelecki

Reputation: 553

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.

Upvotes: 2

Related Questions