Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can kubernetes pods discover each other?

Tags:

kubernetes

I am trying to implement something like the etcd services that uses the consensus algorithm (https://raft.github.io/). In this case, multiple instances of the etcd services need to be aware of each other. For this to happen, if we have 3 pods of etcd instance in a replication controller, the pods need to be able to talk to each other (at least be able to know the IP of self and all the other pods).

Is there a way of achieving this in the replication controller or pod specs without having to use the kubernetes API in the pod container?

like image 638
Gopinath Taget Avatar asked Feb 23 '16 05:02

Gopinath Taget


People also ask

How Kubernetes pods communicate with each other?

Kubernetes defines a network model called the container network interface (CNI), but the actual implementation relies on network plugins. The network plugin is responsible for allocating internet protocol (IP) addresses to pods and enabling pods to communicate with each other within the Kubernetes cluster.

Can Kubernetes pods ping each other?

Kubernetes pods can't ping each other using ClusterIP - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Can 2 pods communicate in Kubernetes?

Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.

How do you check the connection between two pods in Kubernetes?

To find the cluster IP address of a Kubernetes pod, use the kubectl get pod command on your local machine, with the option -o wide . This option will list more information, including the node the pod resides on, and the pod's cluster IP. The IP column will contain the internal cluster IP address for each pod.


1 Answers

You can put a service in front of those pods by giving each pod some label (for example etcd-service=true), and making a kubernetes service with a selector that matches that label. Use the DNS add-on, and you will get a DNS A record for each endpoint in the service. You can read more in the docs here.

like image 122
Paul Morie Avatar answered Oct 10 '22 11:10

Paul Morie