Creating an Inter-Kubernetes-Cluster services using an Internal LoadBalancer

So, say you’ve got two Kubernetes clusters running on GCP and you need to expose a service from Cluster A to Cluster B.

Google Cloud Platform has several ways of doing this but my favorite by far is to use their internal load balancer.

Note: You must have VPC-native (alias IP) enabled when creating your kubernetes cluster on in order for this to work!

Also, the kubernetes clusters and the internal loadbalancers need to be in the same region, so make sure it’s both us-east-1c or whatever you use.

And the critical part here is to create a service that is a LoadBalancer like any other LoadBalancer but use an annotation that essentially allows you to talk between the clusters.

apiVersion: v1
kind: Service
annotations: Internal
app: your-awesome-app
name: your-awesome-app
namespace: default
externalTrafficPolicy: Cluster
- name: your-awesome-app
port: 80
protocol: TCP
targetPort: 80
app: your-awesome-app
sessionAffinity: None
type: LoadBalancer

After you run this, you’ll be able to see an EXTERNAL-IP under services:

And from the other cluster always check and you should be able to hit that endpoint!

> kub exec -it debug-6675b9bd8-84fvh bash
root@debug-6675b9bd8-84fvh:/# http http://10.x.x.x:<your port>
200 response!

Hope this helps!