How can I make communication between instances from different Kubernetes clusters?

2/7/2019

I have an instance in Cluster A and another in Cluster B. My instance in Cluster A will not have it's IP changed but instances in B(which want to access instance in A) might undergo IP changes. So, how can I allow access to the instance in Cluster A without adding the IP addresses of instances in B as it is not a reliable method: whenever my instances in B restart, I will have to add the IPs again. Is VPC Peering an ideal way? How can I perform VPC Peering?

-- Aviral Srivastava
kubernetes

1 Answer

2/7/2019

Lets say you have Pod A in Cluster A and Pod B in Cluster B and you want to access Pod B from Pod A. In this case you have a request from outside Cluster B into Cluster B and, hence, firstly you must have a Kubernetes service for Pod B and secondly you must expose it.

As you stated above you are facing the issue of dynamic IP change after restarting pods. So first make sure to create a Kubernetes Service resource for your pod which will get its own static IP/Cluster-internal DNS entry which will not change when your pod restarts. However, you must also expose this Service to be able to access it from the outside of Cluster B. There are several ways to achieve that:

  1. Use Kubernetes Ingress and route via virtual host or url path to your pod.
  2. Use Kubernetes Service of type Load Balancer for pod B. Access Pod B via DNS entry of the provisioned load balancer. Be aware that this might only be possible from within a public cloud provider.
  3. Use a Kubernetes Service of type Node Port for pod B. Access your Pod by sending your request to any of your Kubernetes Nodes and use the exposed port.
-- Javatar81
Source: StackOverflow