Multi-Cluster Kubernetes
Everything so far happened inside one cluster. Real organisations rarely stop at one: a cluster per environment, per region, sometimes per team. A single cluster is also a single failure domain: one bad admission webhook, one botched upgrade or one control-plane outage takes everything down with it. This lesson covers why teams run several clusters, how traffic finds a healthy one, how configuration reaches all of them, and how services in different clusters talk to each other.
Why more than one cluster?
| Reason | Example |
|---|---|
| Blast radius | A broken CNI upgrade in prod-eu-1 must not touch prod-us-1 |
| Latency and regions | Users in Sydney are served from ap-southeast-2 |
| Data residency | EU personal data stays in EU clusters |
| Isolation | Hard tenancy between customers or teams, beyond what namespaces give |
| Safer upgrades | Build a new cluster on the new version and shift traffic ("blue/green clusters", see Cluster Upgrades) |
| Scale limits | A cluster is tested up to about 5,000 nodes and 150,000 Pods |
The common shape is identical "stamps" or "cells": every production cluster runs the same workloads from the same Git repository, and a global traffic layer spreads users across them.
users
│
global DNS / anycast load balancer
(health checks, weights, geo)
┌─────────────┼──────────────┐
▼ ▼ ▼
prod-eu-1 prod-eu-2 prod-us-1 ◄── same manifests, synced by
Gateway Gateway Gateway Argo CD / Flux from Git
api, web … api, web … api, web …
└──────── data layer: replicated DB / per-region DB ────────┘Working with several clusters from the CLI means several kubeconfig contexts:
$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* prod-eu-1 prod-eu-1 sso-admin shop
prod-eu-2 prod-eu-2 sso-admin shop
prod-us-1 prod-us-1 sso-admin shop
$ kubectl --context prod-us-1 get deploy api -n shop
NAME READY UP-TO-DATE AVAILABLE AGE
api 6/6 6 6 41dGlobal traffic and failover
The simplest global layer is DNS: a managed DNS service (Route 53, Cloud DNS, Azure Traffic Manager, Cloudflare) answers with the address of a healthy cluster, by weight, latency or geography, and health-checks each cluster's Gateway. Failover is not instant: the health checker must see several failures, and resolvers keep cached answers until the TTL expires. The model replays an outage of one of three equally weighted clusters:
CLUSTERS = {"eu-1": 1, "eu-2": 1, "us-1": 1} # DNS weights
CHECK_EVERY, FAIL_THRESHOLD, TTL = 10, 3, 60 # seconds, checks, seconds
DOWN = ("eu-1", 100, 400) # eu-1 broken from t=100 to t=400
def is_up(name, t):
return not (name == DOWN[0] and DOWN[1] <= t < DOWN[2])
in_dns = set(CLUSTERS)
fails = {c: 0 for c in CLUSTERS}
history = [] # DNS answer set over time
for t in range(0, 600, CHECK_EVERY):
for c in CLUSTERS:
fails[c] = 0 if is_up(c, t) else fails[c] + 1
if fails[c] >= FAIL_THRESHOLD and c in in_dns:
in_dns.discard(c)
print(f"t={t:3}s health checks: {c} removed from DNS")
if fails[c] == 0 and c not in in_dns:
in_dns.add(c)
print(f"t={t:3}s health checks: {c} back in DNS")
history.append((t, set(in_dns)))
def answer_at(t):
return [s for ts, s in history if ts <= t][-1]
# Clients resolve, then cache the answer for TTL seconds.
for t in range(80, 241, 20):
cached = answer_at(max(0, t - TTL)) # worst case: answer cached TTL ago
weight = sum(CLUSTERS[c] for c in cached)
failing = sum(CLUSTERS[c] for c in cached if not is_up(c, t))
print(f"t={t:3}s worst-case share of requests failing: {failing / weight:.0%}")t=120s health checks: eu-1 removed from DNS
t=400s health checks: eu-1 back in DNS
t= 80s worst-case share of requests failing: 0%
t=100s worst-case share of requests failing: 33%
t=120s worst-case share of requests failing: 33%
t=140s worst-case share of requests failing: 33%
t=160s worst-case share of requests failing: 33%
t=180s worst-case share of requests failing: 0%
t=200s worst-case share of requests failing: 0%
t=220s worst-case share of requests failing: 0%
t=240s worst-case share of requests failing: 0%
Three failed checks took 20 seconds to remove eu-1 from DNS (checks at t=100, 110, 120), but a client that resolved just before that keeps the cached answer for another 60 seconds: in the worst case a third of requests failed for 80 seconds, detection time plus TTL. Short TTLs (30–60 s) and fast health checks shrink the window; clients that retry another address shrink the error rate inside it. Anycast global load balancers (Google's multi-cluster Gateway, AWS Global Accelerator, Cloudflare) avoid DNS caching altogether, because one IP is announced everywhere and the switch happens in the provider's network.
One configuration, many clusters
With many clusters, kubectl apply by hand is out of the question. GitOps tools (GitOps) handle fleets: Argo CD's ApplicationSet stamps out one Application per registered cluster that matches a label selector, and Flux does the same with one Kustomization per cluster directory.
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: shop
namespace: argocd
spec:
goTemplate: true
generators:
- clusters:
selector:
matchLabels: {env: prod}
template:
metadata:
name: "shop-{{.name}}"
spec:
project: default
source:
repoURL: https://github.com/acme/shop-deploy
targetRevision: main
path: "overlays/{{.metadata.labels.region}}"
destination:
server: "{{.server}}"
namespace: shop
syncPolicy:
automated: {prune: true, selfHeal: true}The generator logic is easy to model: select clusters by labels, then fill the template from each cluster's data. A wave label adds staged rollouts (with ApplicationSet's progressive syncs, or simply one ApplicationSet per wave), so a bad commit reaches the canary cluster before the rest:
clusters = [
{"name": "prod-eu-1", "server": "https://eu1.k8s.example.com", "labels": {"env": "prod", "region": "eu", "wave": "1"}},
{"name": "prod-eu-2", "server": "https://eu2.k8s.example.com", "labels": {"env": "prod", "region": "eu", "wave": "2"}},
{"name": "prod-us-1", "server": "https://us1.k8s.example.com", "labels": {"env": "prod", "region": "us", "wave": "2"}},
{"name": "staging", "server": "https://stg.k8s.example.com", "labels": {"env": "staging", "region": "eu", "wave": "0"}},
]
def generate(selector):
for c in clusters:
if all(c["labels"].get(k) == v for k, v in selector.items()):
yield {"name": f"shop-{c['name']}", "path": f"overlays/{c['labels']['region']}",
"server": c["server"], "wave": int(c["labels"]["wave"])}
apps = sorted(generate({"env": "prod"}), key=lambda a: (a["wave"], a["name"]))
for app in apps:
print(f"wave {app['wave']}: {app['name']:15} {app['path']:12} -> {app['server']}")
def roll_out(commit, unhealthy):
print(f"rollout of commit {commit}:")
for wave in sorted({a["wave"] for a in apps}):
names = [a["name"] for a in apps if a["wave"] == wave]
print(f" sync wave {wave}: {', '.join(names)}")
bad = [n for n in names if n in unhealthy]
if bad:
print(f" {', '.join(bad)} degraded -> later waves stay on the previous commit")
return
print(" all waves healthy")
roll_out("4e1c9a7", unhealthy=set())
roll_out("9b2d415", unhealthy={"shop-prod-eu-1"})wave 1: shop-prod-eu-1 overlays/eu -> https://eu1.k8s.example.com
wave 2: shop-prod-eu-2 overlays/eu -> https://eu2.k8s.example.com
wave 2: shop-prod-us-1 overlays/us -> https://us1.k8s.example.com
rollout of commit 4e1c9a7:
sync wave 1: shop-prod-eu-1
sync wave 2: shop-prod-eu-2, shop-prod-us-1
all waves healthy
rollout of commit 9b2d415:
sync wave 1: shop-prod-eu-1
shop-prod-eu-1 degraded -> later waves stay on the previous commit
Services across clusters
Sometimes a service in one cluster must call a service in another: a shared authentication service, or a fallback when the local copy is down. Options, from simplest to most integrated:
| Approach | How it works |
|---|---|
| Public/internal endpoints | Expose the service through a Gateway with a DNS name; call it like any external API |
Multi-Cluster Services API (ServiceExport / ServiceImport) |
Export a Service; it becomes resolvable as <svc>.<ns>.svc.clusterset.local in every cluster of the set (GKE, Submariner, Cilium) |
| Cilium ClusterMesh | Connect Pod networks; a Service annotated service.cilium.io/global: "true" load-balances across clusters |
| Istio multi-cluster | One mesh spanning clusters with east-west gateways; mTLS identities and traffic policy work across clusters |
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceExport
metadata:
name: auth # same name and namespace as the Service to export
namespace: identityMeshes and Envoy-based gateways usually prefer local endpoints and fail over by priority: same zone, then same region, then other regions. Envoy does not wait for zero healthy endpoints: with its default overprovisioning factor of 1.4, a priority level keeps all traffic only while at least about 71% (1/1.4) of its endpoints are healthy, and the rest spills to the next level:
def spill(levels, factor=1.4):
"""levels: list of (name, healthy, total) in priority order -> share of traffic per level."""
remaining, shares = 100.0, []
for name, healthy, total in levels:
capacity = min(100.0, healthy / total * 100 * factor)
take = min(remaining, capacity)
shares.append((name, take))
remaining -= take
return shares
scenarios = {
"all healthy": [("eu-1 local", 6, 6), ("eu-2 same region", 6, 6), ("us-1 remote", 6, 6)],
"2 of 6 local down": [("eu-1 local", 4, 6), ("eu-2 same region", 6, 6), ("us-1 remote", 6, 6)],
"eu-1 down, eu-2 weak": [("eu-1 local", 0, 6), ("eu-2 same region", 3, 6), ("us-1 remote", 6, 6)],
}
for title, levels in scenarios.items():
print(f"{title:22}", " ".join(f"{n}: {s:.0f}%" for n, s in spill(levels)))all healthy eu-1 local: 100% eu-2 same region: 0% us-1 remote: 0%
2 of 6 local down eu-1 local: 93% eu-2 same region: 7% us-1 remote: 0%
eu-1 down, eu-2 weak eu-1 local: 0% eu-2 same region: 70% us-1 remote: 30%
The hard part: state
Stateless services replicate across clusters easily; data does not. Typical answers are a managed multi-region database (Spanner, Aurora Global, Cosmos DB), one primary region with asynchronous replicas elsewhere (failover means promoting a replica and accepting a few seconds of lost writes), or partitioning so each region owns its own users' data. Persistent volumes are tied to one cluster and zone (PersistentVolumes); tools such as Velero back up objects and volume snapshots so you can restore a namespace into another cluster, which is a disaster-recovery tool, not live failover.
Tip: Practise failover. A runbook nobody has executed is a hypothesis. Drain one cluster's weight to zero during business hours on a regular schedule and watch what breaks.
Learn more: GitOps · Managed Kubernetes · Service Meshes · Docker Swarm high availability
Test yourself
A cluster fails and DNS health checks remove it after 30 seconds. The record's TTL is 300 seconds. Roughly how long can some clients keep sending traffic to the dead cluster?
- 30 seconds
- Up to about 330 seconds
- 0 seconds
- Exactly 300 seconds, starting at the failure
What does an Argo CD ApplicationSet with a cluster generator do?
- Creates new clusters
- Creates one Application per registered cluster matching a selector, from a template
- Merges clusters into one
- Backs up etcd
Which DNS name does the Multi-Cluster Services API give an exported Service?
- svc.cluster.local
- <svc>.<ns>.svc.clusterset.local
- <svc>.global
- <cluster>.<svc>.local