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

John Jung
John Jung
Oct 23, 2018 · 2 min read

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!

Sign up for GCP using the link below for an additional $50! ($350 total for new users).

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store