The Ops Community ⚙️

Cover image for Scaling Kubernetes to multiple clusters and regions
Daniele Polencic
Daniele Polencic

Posted on

Scaling Kubernetes to multiple clusters and regions

TL;DR: In this tutorial, you will learn how to create, connect and operate three Kubernetes clusters in different regions: North America, Europe and South East Asia.

One interesting challenge with Kubernetes is deploying workloads across several regions.

While you can technically have a cluster with several nodes located in different regions, this is generally regarded as something you should avoid due to the extra latency.

Another popular alternative is to deploy a cluster for each region and find a way to orchestrate them.

Placing nodes in a multicluster setup

But before discussing solutions, let's look at the challenges of a multicluster & multi-cloud setup.

When you orchestrate several clusters, you have to face the following issues:

  • How do you decide how to split the workloads?
  • How does the networking work across regions?
  • What should I do with stateful apps/data?

Challenges of running a Kubernetes multicluster setup

Let's try to answer some of those questions.

To tackle the first (scheduling workloads), I used Karmada.

With Karmada, you can create deployments with kubectl and distribute them across several clusters using policies.

Karmada takes care of propagating them to the correct cluster.

The project is similar (in spirit) to kubefed.

Goegraphically distributed Kubernetes cluster with Karmada

Karmada uses a Kubernetes cluster as the manager and creates a second control plane that is multicluster aware.

This is particularly convenient because kubectl "just works" and is now multicluster aware.

In other words, you can keep using kubectl, but all the commands can apply resources across clusters and aggregate data.

Each cluster has an agent that issues commands to the cluster's API server.

The Karmada controller manager uses those agents to sync and dispatch commands.

Karmada client-server architecture and control plane

Karmada uses policies to decide how to distribute your workloads.

You could have policies to have a deployment equally distributed across regions.

Or you could place your pods in a single region.

Orchestrating workloads across several regions and clouds with Karmada policies

Karmada is essentially a multicluster orchestrator but doesn't provide any mechanism to connect the clusters' networks.

Traffic routed to a region will always reach pods from that region.

Traffic routed to a cluster will always reach pods from that cluster

But you can use a service mesh like Istio to create a network that spans several clusters.

Istio can discover other instances in other clusters and forward the traffic to other clusters.

Istio multi-cluster setup

But how does the traffic routing work?

For every app in your cluster, Istio injects a sidecar proxy.

All traffic from and to the app goes through the proxy.

The Istio control plane can configure the proxy on the fly and apply routing policies.

Architecture of a service mesh with proxy side cars

In a multicluster setup, Istio instances share endpoints.

When a request is issued, the traffic is intercepted by the proxy sidecar and forwarded to one of the endpoints amongst all endpoints in all clusters.

Kubernetes endpoints are shared so that traffic can be forwarded from one cluster to the other

Since Istio's traffic routing rules let you easily control the flow of traffic and API calls between services, you can have traffic reaching a single region even if pods are deployed in each region.

Or you could create rules to shift traffic from one region to another.

Multi cluster traffic management with Istio

Nice in theory, but does it work in practice?

I built a proof of concept with Terraform so that you can recreate it in 5 clicks here: https://github.com/learnk8s/multi-cluster

And here's a demo of it.

Multi cluster Kubernetes setup

I also installed Kiali to visualise the traffic flowing in the clusters in real time.

Multi cluster Kiali demo

If you wish to see this in action, you can watch my demo here.

And finally, if you've enjoyed this thread, you might also like the Kubernetes workshops that we run at Learnk8s https://learnk8s.io/training or this collection of past Twitter threads https://twitter.com/danielepolencic/status/1298543151901155330

Until next time!

Top comments (22)

Collapse
 
lovemoney profile image
kyeh mvrs • Edited

Super interesting challenge, orchestrating Kubernetes across regions! It really highlights how complex distributed systems can get. Speaking of organizing unique things, I was just checking out a birth flower chart earlier today to see what my birth flower means. Such a neat little personal detail!

Collapse
 
polytrackgames profile image
toripialiw

that's a good tutorial! Snow Rider is an addictive browser game that mixes heart-pounding speed, dangerous environmental hazards, and rewarding shop mechanics into a cohesive loop, allowing players to test their survival skills against giant snowballs and cliffs.

Collapse
 
df_ea31db9ef368c7c61 profile image
darkwill

The proof of concept with Terraform caught my eye; it's lightweight and effective! Using it to recreate a multi-cluster setup in just a few clicks during my morning coffee break made the process a breeze. Z Image

Collapse
 
tyde_hodge_d805b16aadf8e6 profile image
Tyde Hodge

This is a solid, practical introduction to real-world Kubernetes scaling problems. It clearly explains why multi-region clusters matter, outlines the core challenges, and introduces Karmada without yahoo maps overselling it. The focus on latency, workload placement, and stateful complexity makes the tutorial useful for engineers planning beyond single-cluster deployments.

Collapse
 
df_ea31db9ef368c7c61 profile image
darkwill

The idea of using Karmada for deploying workloads across regions is very intriguing. It simplifies multi-cluster orchestration with its policy-based approach, even though networking between clusters still relies on Istio Banana AI

Collapse
 
fordimmense profile image
Only Chamboo

Players are kept interested by this bloodmoney reward-consequence balance because they are always forced to balance the long-term advantages of maintaining discretion and professionalism against the risks of a short, ostentatious fix.

Collapse
 
otis_amity_fcd96e009225ae profile image
Otis Amity

Deploying Kubernetes Agario globally. While it is possible to aggregate nodes from multiple regions into a single cluster, this introduces significant latency between nodes, which impacts application performance and cluster stability. This is a major issue that cloud architects face on a regular basis.

Collapse
 
lovemoney profile image
kyeh mvrs

This is a great guide for managing multiple Kubernetes clusters! It's amazing how much effort goes into keeping everything running smoothly. Speaking of managing resources, have you ever played love money game online? It's a fun way to practice making tough decisions, just like optimizing cloud infrastructure!

Collapse
 
erik_dickens_43614fcd1a44 profile image
Erik Dickens • Edited

Great explanation of the challenges of multiclustering with Kubernetes. The complexity of balancing and networking across regions is very reminiscent of the fun unpredictability of geometry dash spam, where each match tests our ability to adapt.

Collapse
 
polytrackgames profile image
toripialiw

polytrackgames is a fast-paced and captivating game that blends time-trial strategy, level creation, and arcade physics into one seamless experience, allowing players to play as a skilled course creator.