How can pods within a kubernetes replica set discover and talk to each other without the kubernetes API?
The solution is to use a headless service. For example, we can deploy a headless service called myservice-discovery
. Because the service is headless, it does not do any load-balancing or get a cluster ip address. To get the ip addresses of the pods, you then query the DNS server for myservice-discovery.mycluster
to get a list of A records.
You can also set up a second normal (non-headless) service if the pods also need to be accessible to other services and pods.