Service to Service Call Pattern — Multi-Cluster Ingress

Biju Kunjummen
3 min readJan 17, 2022

Multi-Cluster Ingress is a neat feature of Anthos and GKE (Google Kubernetes Engine), whereby a user accessing an application that is hosted on multiple GKE clusters, in different zones is directed to the right cluster that is nearest to the user!

So for eg. consider two GKE clusters, one in us-west1, based out of Oregon, USA and another in europe-north1, based out of Finland. An application is installed to these two clusters. Now, a user accessing the application from US will be lead to the GKE cluster in us-west1 and a user coming in from Europe will be lead to the GKE cluster in europe-north1. Multi-cluster Ingress enables this easily!

Enabling Multi-Cluster Ingress

Alright, so how does this work.

Let me once again assume that I have two clusters available in my GCP project, one in us-west1-a zone and another in europe-north1-a, and an app called “Caller” deployed to these two clusters. For a single cluster, the way to get traffic into the cluster from a user outside of it is typically done using an “Ingress”

This works great for a single cluster, however not so for a bunch of clusters. A different kind of an Ingress resource is required that spans GKE clusters and this is where a Multi-Cluster ingress comes in — an ingress that spans clusters.

Multi-Cluster Ingress is a Custom resource provided by GKE and looks something like this:

multi-cluster-ingress.yaml

It is defined in one of the clusters, designated as a “config” cluster.

See how there is a a reference to “sample-caller-mcs” above. This is pointing to another custom resource, this time a “MultiClusterService” resource, think of it just like a service in a single cluster abstracting out a set of pods, but spread across multiple clusters.

A definition for such a resource, looks almost like a Service and here is the one for “sample-caller-mcs”:

Now that there is a MultiClusterIngress defined pointing to a MultiClusterService, these are managed by the different operators that understand these resources under the covers:

1. A load balancer is created which uses an ip advertised using anycast — better details are here. These anycast ip’s help get the request through to the cluster closest to the user.

2. A Network Endpoint Group(NEG) is created and kept in sync for every cluster that matches the definition of MultiClusterService. These NEG’s are used as the backend of the loadbalancer.

Sample Application

I have a sample set of applications and deployment manifests available here that demonstrates Multi-Cluster Ingress. There are instructions to go with it here. This brings up an environment which looks like this:

Now to simulate a request coming in from us-west1-a is easy for me since I am in US, another approach is to simply spin up an instance in us-west1-a and use that to make a request the following way:

And the “caller” invoked should be the one in us-west1-a, similarly if the request is made from an instance in europe-north1-a:

The “caller” invoked will be the one in europe-north1-a!!

Conclusion

This really boggles my mind, being able to spin up two clusters on two different continents(North America and Europe), and having a request from the user directed to the one closest to them, in a fairly simple way. There is a lot going on under the covers, however this is abstracted out using the resource types of MultiClusterIngress and MultiClusterService.

My repository has samples available to spin up the clusters and deploy apps to it — https://github.com/bijukunjummen/sample-service-to-service

Originally published at http://www.java-allandsundry.com.

--

--

Biju Kunjummen

Sharing knowledge about Java, Cloud and general software engineering practices