Is it possible for a pod running in a satrefulset to get the hostname of the all the pod running in different statefulset?

8/14/2020

I have a pod running in a statefulset but it needs to know the hostname or address of all pods running in another statefulset to communicate with them. The second statefulset is being created by a separate helm chart. Can the pod work this out dynamically? Can I inject this information into the pod through an env similar to setting .Status.ip?

Edit: Each statefulSet has its own headless service

-- atlantis.pd
kubernetes
kubernetes-helm
kubernetes-statefulset

1 Answer

8/17/2020

As discussed in the comments, the way to go here is to use a service-resource as this will give you a static DNS within the cluster to reach all the pods that a targeted by that service.

The DNS for the service is:

  • the services name if you access it from within the same namespace
  • <my-service-name>.<namespace-name>.svc.cluster.local if you access it from another namespace, and where cluster.local is the clusters domain that might differ from cluster to cluster depending on the clusters configuration

If you further need more configuration options, e.g. when you want to deploy your chart into different cloud environments where the clusters-domain might actually differ, you can use kustomize.io to adjust your configuration at apply time.

-- David Losert
Source: StackOverflow