I have the following Kubernetes YAML with a StatefulSet I use to deploy a PostgreSQL cluster with Patroni. However, the question is relative to how Kubernetes registers Pod names in CoreDNS.
According to this documentation in the Stable Network ID section if I create a Headless service called spilodemo-svc
for my Pods I can access them using the short hostname (podname.servicename):
spilodemo-0.spilodemo-svc
Basically, my code worked properly for a long time on a K8s cluster deployed with kubeadm on VirtualBox and Vagrant. Today I wanted to deploy it on IBM Cloud but the hostname above didn't work and the strange thing is that when I repeated my tests on Vagrant/VirtualBox again I wasn't able to have it working anymore and I do not know why.
Now the YAML deploys Spilo that is an open-source project developed by Zalando that is a Docker image with Patroni and PostgreSQL. My code comes from their example here.
Basically, they create a ClusterIP Service (and not a Headless) with no Selector. Under these conditions, Kubernetes doesn't create an Endpoint in it. For this reason, we have an Endpoint in the YAML with the same name of the service (it seems this is the binding Kubernetes expect).
Spilo has Python code that always keeps updated this Endpoint with the IP of the primary node.
The StatefulSet has the field serviceName equal to the name of the Service:
serviceName: spilodemo-svc
and, according to the documentation, this guarantees that Kubernetes creates an entry in CoreDNS for this short hostname (podname.servicename):
spilodemo-0.spilodemo-svc
and it worked for a long time until today and nothing happened in the meanwhile. To be honest I never fully understand how the DNS name spilodemo-0.spilodemo-svc
worked so far since it uses a ClusterIP service instead of a Headless one.
Another strange thing is that the Zalando team uses another Headless service that I called spilodemo-config
and according to a comment in their code, it should avoid that Kubernetes delete the Endpoint but this doesn't make much sense to me.
However, today I also tried to convert the Service into a Headless one removing the spilodemo-config
one but no luck. Kubernetes only create the entry for the service in the CoreDNS:
spilodemo.spilons.svc.cluster.local
but not the one for each Pod:
spilodemo-0.spilodemo-svc
spilodemo-1.spilodemo-svc
spilodemo-2.spilodemo-svc
Can anyone help me to figure out what's going on with my YAML file and how I can get the three short hostnames above working in CoreDNS?
PS On Stackoverflow I found these discussions:
- Hostname of pods in the same StatefulSet can not be resolved
- Stateful Pod hostname doesn't resolve but they don't address my issue.