From point A to point B
Point A: everything you've seen of Cilium lives inside one cluster. Identities, policies and observability stop at its border. Point B: by the end of this chapter you'll be able to connect three clusters with Cluster Mesh, publish a global service with failover between clusters and write policies that recognize pods from other clusters.
Why several clusters
- Organizational structure: one cluster per business unit or cost center.
- Resilience: stretching a cluster across regions is a bad idea (etcd doesn't tolerate latency well), so you deploy one cluster per site.
- Scale: Kubernetes starts to struggle at around 10,000 nodes.
- Multicloud: often for regulatory reasons, in banking or healthcare, so you don't depend on a single provider.
Don't confuse this with having development, testing and production clusters: those environments normally should not talk to each other.
What Cluster Mesh solves
Without Cluster Mesh, the usual option is to treat the other clusters as something external: publish services with LoadBalancer, announce them over BGP and spread the IPs with DNS, or put an external load balancer in front. It works, but clients have to do their own load balancing and their own failover, taking a cluster out means waiting for DNS to expire, and policies have to talk about IP ranges.
Cluster Mesh adds two capabilities:
- Cross-cluster service discovery: a global service has backends in several clusters. The application keeps calling its usual local service; eBPF picks the backend, preferring the local one if you want.
- Cross-cluster policies: identities are shared, so a policy can allow "the frontend in cluster X" by its labels.
Cluster Mesh does not create connectivity between clusters: the network has to let every node reach every other by IP (and the pods too, if you use native routing). They don't need to share a layer 2 network.
Architecture
Metadata travels between apiservers; application traffic, from node to node. Diagram: The House of Routing.
- No central point: there's no coordinator cluster. Each cluster knows the way to the others; with n clusters there are n(n−1)/2 connections. The mesh keeps working even if it splits into groups.
- clustermesh-apiserver: reads from its cluster's Kubernetes API (services, endpoints, identities) and exposes it to the other clusters from its own etcd, in memory and without replicas. It's not the Kubernetes etcd and it doesn't store original data.
- KVStoreMesh: on by default since Cilium 1.16, it caches the remote clusters' information for the local agents.
- Datapath: application traffic never goes through the apiserver; it goes straight from node to node, through a tunnel or over native routes.
Connect three clusters
Requirements to join the mesh:
| Requirement | Detail |
|---|---|
| Cilium as the CNI | In every cluster, ideally on the same minor version |
| Same routing mode | All with tunnel or all with native routing |
| Non-overlapping PodCIDR | Each cluster with its own pod range |
| L3 connectivity | Between all nodes (and pods, if it's native routing) |
| Unique name and ID | A different cluster.name and cluster.id in each cluster |
| Same maximum mesh size | 255 clusters (default) or 511, which halves the identities per cluster |
We'll use three kind clusters with the kind-cilium.yaml from chapter 3. They all share the kind Docker network, so their nodes can already reach each other:
| cluster.name | cluster.id | PodCIDR |
|---|---|---|
| vancouver | 1 | 10.1.0.0/16 |
| madrid | 2 | 10.2.0.0/16 |
| santiago | 3 | 10.3.0.0/16 |
The clusters have to trust each other. The simplest way is for them to share the same certificate authority: you install the first one and copy its cilium-ca secret to the others before installing Cilium on them.
CLUSTERS=(vancouver madrid santiago)
for c in "${CLUSTERS[@]}"; do kind create cluster --config kind-cilium.yaml --name $c; done
for i in "${!CLUSTERS[@]}"; do
c=${CLUSTERS[$i]}; id=$((i + 1))
if [ $id -gt 1 ]; then
# Same CA as vancouver, without the original object's own metadata
kubectl --context kind-vancouver -n kube-system get secret cilium-ca -o yaml \
| yq 'del(.metadata.resourceVersion, .metadata.uid, .metadata.creationTimestamp)' \
| kubectl --context kind-$c create -f -
fi
helm install cilium cilium/cilium --version 1.20.3 -n kube-system \
--kube-context kind-$c \
--set cluster.name=$c \
--set cluster.id=$id \
--set ipam.operator.clusterPoolIPv4PodCIDRList=10.$id.0.0/16
done
Now turn on the Cluster Mesh apiserver in each cluster and connect them. In kind we expose it through NodePort; in production, use a LoadBalancer with a stable IP:
for c in "${CLUSTERS[@]}"; do
cilium clustermesh enable --context kind-$c --service-type NodePort
done
for c in "${CLUSTERS[@]}"; do cilium clustermesh status --context kind-$c --wait; done
# Each pair only once: the connection goes both ways
cilium clustermesh connect --context kind-vancouver --destination-context kind-madrid
cilium clustermesh connect --context kind-vancouver --destination-context kind-santiago
cilium clustermesh connect --context kind-madrid --destination-context kind-santiago
cilium clustermesh status --context kind-madrid --wait
# All nodes are connected to all clusters
The CLI is handy for learning. In production, declare the mesh in the Helm values (clustermesh.useAPIServer, clustermesh.config.enabled and the clustermesh.config.clusters list with each cluster's name, IPs and port) and keep it in Git.
Validate the mesh with the built-in connectivity test:
cilium connectivity test --context kind-vancouver --multi-cluster kind-madrid
The test works in pairs and takes several minutes. With many clusters, choose which pairs to test.
cilium clustermesh status tells you which cluster isn't connecting and suggests a KVStoreMesh diagnostic command. A typical error is x509: certificate signed by unknown authority: the clusters don't share a CA.Global services and affinity
A service is global when it exists with the same name and namespace in several clusters and carries the service.cilium.io/global: "true" annotation. Service IPs don't have to match.
Local cluster first; if there are no healthy backends, another cluster. Diagram: The House of Routing.
for c in "${CLUSTERS[@]}"; do
kubectl --context kind-$c create deployment echo \
--image=hashicorp/http-echo -- /http-echo -text="response from $c"
kubectl --context kind-$c apply -f - <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: echo
annotations:
service.cilium.io/global: "true" # in quotes: it's a string
spec:
selector:
app: echo
ports:
- port: 80
targetPort: 5678
EOF
done
kubectl --context kind-madrid run client --image=nicolaka/netshoot -- sleep infinity
for i in $(seq 9); do kubectl --context kind-madrid exec client -- curl -s http://echo; done
# response from santiago / vancouver / madrid … at random
| Annotation | Effect |
|---|---|
service.cilium.io/global: "true" | The service uses backends from every cluster |
service.cilium.io/shared: "false" | This cluster uses remote backends, but doesn't share its own |
service.cilium.io/affinity: "local" | Prefers local backends; if there are none, uses remote ones |
service.cilium.io/affinity: "remote" | Prefers remote backends (useful for maintenance) |
kubectl --context kind-madrid annotate service echo service.cilium.io/affinity=local
for i in $(seq 5); do kubectl --context kind-madrid exec client -- curl -s http://echo; done
# response from madrid (always)
kubectl --context kind-madrid scale deployment echo --replicas=0
for i in $(seq 5); do kubectl --context kind-madrid exec client -- curl -s http://echo; done
# response from vancouver / santiago: automatic failover
Affinity only affects the cluster where you configure it: there's no central view of the service. And always test cross-region failover in a non-production environment: if the remote cluster is far away, the extra latency can make things worse instead of saving them.
Cross-cluster policies
Identities are shared across the mesh, so a policy can select pods from other clusters with the special label io.cilium.k8s.policy.cluster.
Up to 1.18, a policy with no cluster selected pods from every cluster. Since 1.19, if you don't specify the cluster, the policy only selects pods from the local cluster. To allow traffic from another cluster, name it explicitly.
# echo-policy.yaml · in madrid and santiago: echo only accepts the frontend from vancouver
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: echo-from-vancouver
spec:
endpointSelector:
matchLabels:
app: echo
ingress:
- fromEndpoints:
- matchLabels:
role: frontend
io.cilium.k8s.policy.cluster: vancouver
toPorts:
- ports:
- port: "5678"
protocol: TCP
for c in madrid santiago; do kubectl --context kind-$c apply -f echo-policy.yaml; done
kubectl --context kind-vancouver delete deployment echo # vancouver will only use remote backends
kubectl --context kind-vancouver run frontend --labels role=frontend \
--image=nicolaka/netshoot -- sleep infinity
kubectl --context kind-vancouver run other --image=nicolaka/netshoot -- sleep infinity
kubectl --context kind-vancouver exec frontend -- curl -s -m 3 http://echo # madrid or santiago responds
kubectl --context kind-vancouver exec other -- curl -s -m 3 http://echo # timeout
To accept the frontend from any cluster, use matchExpressions with key: io.cilium.k8s.policy.cluster and operator: Exists. Remember that policies aren't synchronized either: apply each one in the cluster where it needs to act.
Certificates
Everything that travels between Cluster Mesh components is encrypted with TLS. That way nobody can read the metadata or impersonate another cluster. Four certificates are involved:
| Secret | Who presents it |
|---|---|
clustermesh-apiserver-server-cert | The apiserver's etcd, to all its clients |
clustermesh-apiserver-admin-cert | The apiserver, to its own etcd |
clustermesh-apiserver-remote-cert | The apiserver, to the remote clusters' etcd |
clustermesh-apiserver-local-cert | The agents, to their local apiserver's etcd |
Two trust models:
- A shared CA (what you did in the lab): simple and scalable. Adding a cluster doesn't force you to touch the others.
- One CA per cluster with a common trust bundle: avoids sharing private keys, but every new cluster forces you to update the bundle everywhere. With many clusters it becomes unmanageable.
For your own corporate CA, follow the official documentation: it's a more complex setup.
Most teams will never turn on Cluster Mesh. But if there's a chance, give each cluster a different pod range starting today. That way you can join them later without migrating IPAM.
# Cleanup
for c in "${CLUSTERS[@]}"; do kind delete cluster --name $c; done
Challenge
Answer before you open the solution.
1. Does application traffic go through the clustermesh-apiserver?
No. The apiserver only shares metadata; traffic goes from node to node.
2. What does a service need to be global?
The same name and namespace in each cluster and the service.cilium.io/global: "true" annotation, in quotes.
3. You want to use local backends and only jump to another cluster if they fail. What do you annotate?
service.cilium.io/affinity: "local", on the service in the cluster where the client is.
4. In Cilium 1.20, a policy allows role: frontend without specifying a cluster. Where does it accept traffic from?
Only from the local cluster. Since 1.19 you have to name the cluster with io.cilium.k8s.policy.cluster.
What you take away
- Cluster Mesh shares services and identities between clusters, with no central point.
- You provide the L3 connectivity; Cilium provides discovery and policies.
- Non-overlapping PodCIDR, unique name and ID, the same routing mode and a trusted CA.
- Global services with annotations; local affinity gives you automatic failover.
- Since Cilium 1.19, policies must name the remote cluster explicitly.
In the next chapter: accessing the cluster from outside, with BGP and layer 2 announcements.
Official resources
- Multi-Cluster (Cluster Mesh)docs.cilium.io
- Setting up Cluster Meshdocs.cilium.io
- Cluster Mesh: Network Policydocs.cilium.io
- Global Servicesdocs.cilium.io
- Multi-Cluster Services APIdocs.cilium.io
- Cilium: Up and Running (book)isovalent.com
Source and credits. This chapter summarizes and paraphrases the official book Cilium: Up and Running by Nico Vibert, Filip Nikolic and James Laverack (O'Reilly Media, 2026). The summary was produced with AI and reviewed, verified and approved by Jesús Espinoza. The diagrams and code examples are original work by The House of Routing and were checked against the official Cilium documentation. Cilium: Up and Running, the cover image, and related trade dress are trademarks of O'Reilly Media, Inc. This content is not affiliated with or endorsed by O'Reilly Media or Isovalent.