Are Headless Services updated "atomic" in Kubernetes?

4/15/2021

I am working on a Kubernetes integration of the database Apache IoTDB which supports a Cluster mode. Currently, to start a cluster each node needs to know the IP adresses of all other nodes in its "ensemble" upfront, before starting.

I think the default approach to this in Kubernetes would generally be to use a StatefulSet and a headless Service. And the startup loop I scratched would be something like this

  1. start each pod with a container which contains a "pre-start" script
  2. In the pre-start script wait until all other pods of the set are started and get all their ip adresses from the headless service)
  3. update the configs / env variables with all cluster ip adresses
  4. start the iotdb instance(s)

So the only question I have is for step 2: When do I know that all pods are started? Is the update of the DNS / A records of the headless Service atomic in the sense that I see all pods or no pod? OR do I have to query the API Server separately to see the number of replicas and then wait until I got all their records from the headless service?

Or is there a more kubernetes-like way to achieve that?

Thanks already!

-- Julian
kubernetes

1 Answer

4/15/2021

When a DNS address of a headless service is resolved, it returns a list of Pods (ie. IPs) from an underlying endpoint object. The endpoint object always holds the list of Ready pods.

So, you will get the list of Ready pods of that moment on resolving headless service DNS.

-- Kamol Hasan
Source: StackOverflow