I have a statefulset with 3 members. They are accessible from inside the cluster with something like:
podname-{0..n}.service.default.svc.cluster.local
I'm using the Kubernetes API from a Controller. I just created the Statefulset with:
import (
"k8s.io/client-go/kubernetes"
appsv1 "k8s.io/api/apps/v1"
)
...
s := appsv1.StatefulSet{ /* some data */ }
kubernetes.AppsV1().StatefulSets(nameSpace).Create(s)
Let's assume everything worked correctly, and after a few minutes I have 3 running Pods. How can I get the Pod DNS entries for the newly created Pods?
I know I can build the DNS with:
fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local", s.Name, idx, service, S.Namespace)
But I'm finding some issues:
StatefulSet
cluster.local which is not necessarily trueWhat I think it should exists (but I'm not sure if it really exists), is an API, that given a StatefulSet will allow me to know the DNS names of the Replicas that were created. Does an API like this exists?
When you create the headless Service with the StatefulSet, it should create DNS SRV entries. You can query that to get a list of all host names of the pods corresponding to the headless Service without knowing the number. For example, if using Python you can do:
>>> import dns
>>> for item in dns.resolver.query('your-app-name-headless', 'SRV'): item
...
<DNS IN SRV rdata: 10 25 0 2555bb89.your-app-name-headless.your-project.svc.cluster.local.>
<DNS IN SRV rdata: 10 25 0 830bdb18.your-app-name-headless.your-project.svc.cluster.local.>
<DNS IN SRV rdata: 10 25 0 aeb532de.your-app-name-headless.your-project.svc.cluster.local.>
<DNS IN SRV rdata: 10 25 0 a432c21f.your-app-name-headless.your-project.svc.cluster.local.>
See:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With