Ramboo19
Ramboo19

Reputation: 189

Communication from Pod to Pod

I have a node with 2 pods. Each pod will need to speak to each other. Problem being that i do not want to hardcode the IPs in for the communication.

Similar to a DNS service, i need something (that does not change) that can sit above the pod ip and allow me to still communicate between the pods.

Upvotes: 1

Views: 3854

Answers (1)

Shahriar
Shahriar

Reputation: 13804

I can see two solution

Solution 1: Use Service

If they are not from same controller and if they have their own Service, they can use Service to communicate with each other.

Service 1 - > Pod 1
Service 2 - > Pod 2

Use this Service

Pod 1: Service 2 -> Pod 2
Pod 2: Service 1 -> Pod 1

Solution 2: Use StatefulSet

If they need same Controller, you can use StatefulSet.

For a StatefulSet with N replicas, each Pod in the StatefulSet will be assigned an integer ordinal, in the range [0,N], that is unique over the Set

That means Pod name will be: $(statefulset name)-$(ordinal)

If you have StatefulSet named nginx with replica 2, you will have two Pod nginx-0 & nginx-1.

As each Pod is created, it gets a matching DNS subdomain, taking the form: $(podname).$(governing service domain)

Pod nginx-0: nginx-1.{service-account}.{namespace}.svc.cluster.local -> nginx-1

Pod nginx-1: nginx-0.{service-account}.{namespace}.svc.cluster.local -> nginx-0

Using this Stable Network ID, these Pods can communicate with each other.

Upvotes: 7

Related Questions