Multi-Cluster Architecture
A comprehensive guide to multi-cluster Kubernetes architecture covering federation, cluster federation v2, multicluster networking, disaster recovery, service mesh, and operational best practices for managing multiple Kubernetes clusters.
Multi-cluster architecture refers to the practice of running multiple Kubernetes clusters to meet various operational requirements. Organizations adopt multi-cluster strategies for reasons including high availability, disaster recovery, geographic distribution, regulatory compliance, environment isolation, and cost optimization.
Managing multiple clusters introduces significant complexity in areas like service discovery, networking, policy enforcement, and application deployment. This guide covers the patterns, tools, and best practices for successful multi-cluster operations.
- High Availability: Distribute workloads across clusters to survive regional failures
- Disaster Recovery: Maintain standby clusters for business continuity
- Latency Optimization: Place workloads geographically closer to users
- Compliance: Keep data in specific regions per regulatory requirements
- Cost Management: Use different instance types or spot instances in different clusters
Active-Active
Active-Standby
Development/Staging/Production
Compliance/Regulatory
Cluster Federation (kubefed) is a Kubernetes project that provides a way to manage multiple clusters from a single control plane. It enables you to deploy and manage applications across multiple clusters using a federated API.
Federated Resources
Federated Services
Replica Scheduling
Override Policies
# Install kubefed
kubectl apply -f https://github.com/kubernetes-sigs/kubefed/releases/latest/download/federation-v2.yaml
# Join a cluster to federation
kubefedctl join cluster-name --cluster-context cluster-name --host-cluster-context host-cluster
# Create Federated Deployment
apiVersion: types.kubefed.io/v1beta1
kind: FederatedDeployment
metadata:
name: nginx
namespace: default
spec:
template:
metadata:
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
placement:
clusters:
- name: cluster-a
- name: cluster-b
- name: cluster-c
# Override for specific cluster
apiVersion: types.kubefed.io/v1beta1
kind: FederatedDeployment
metadata:
name: nginx
namespace: default
spec:
template: ...
placement:
clusters:
- name: cluster-a
highPriority: true
- name: cluster-b
overrides:
- clusterName: cluster-b
clusterOverrides:
- path: "/spec/replicas"
value: 5
Connecting clusters across different networks (cloud providers, on-premise, regions) requires specialized networking solutions. Here are the primary approaches:
VPN/Tunneling
Service Mesh (Istio, Linkerd)
Cloud Native Networking
Cloud Provider Solutions
# Istio Multi-Cluster Configuration
# Primary cluster configuration
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
name: istio-primary
spec:
meshConfig:
trustDomain: cluster-a.local
values:
global:
multiCluster:
clusterName: cluster-a
network: network-a
# Remote cluster configuration
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
name: istio-remote
spec:
meshConfig:
trustDomain: cluster-b.local
values:
global:
multiCluster:
clusterName: cluster-b
network: network-b
# Enable cross-cluster service discovery
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name: cross-cluster-service
spec:
hosts:
- service-b.cluster-b.svc.cluster.local
ports:
- number: 8080
name: http
protocol: HTTP
resolution: DNS
location: MESH_INTERNAL
Multi-cluster architecture is the foundation of robust disaster recovery strategies. Here are the key patterns and tools for DR.
Backup & Restore
Cross-Cluster Replication
Global Load Balancing
Active-Passive DR
# Velero backup configuration
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
name: default
namespace: velero
spec:
provider: aws
objectStorage:
bucket: my-backup-bucket
prefix: backups
config:
region: us-east-1
---
apiVersion: velero.io/v1
kind: VolumeSnapshotLocation
metadata:
name: default
namespace: velero
spec:
provider: aws
config:
region: us-east-1
# Create a backup
velero backup create full-backup --include-namespaces default,production
# Schedule daily backups
velero schedule create daily-backup --schedule="0 2 * * *" --include-namespaces default,production
# Restore to DR cluster
velero restore create --from-backup full-backup
# Verify restore
velero restore describe full-backup
- Regularly test DR procedures in a non-production environment
- Maintain backup replication across regions
- Document and automate failover procedures
- Monitor backup status and alert on failures
- Define RPO (Recovery Point Objective) and RTO (Recovery Time Objective)
A service mesh can span multiple clusters, providing unified service discovery, traffic management, and security across cluster boundaries. Istio and Linkerd both support multi-cluster configurations.
# Istio Multi-Cluster with Remote Secrets
# Export control plane certificate from primary cluster
istioctl x authn tls-cert \
--cluster cluster-a \
--context cluster-a-context \
--namespace istio-system
# Create remote secret in secondary cluster
istioctl x create-remote-secret \
--cluster-name cluster-a \
--context cluster-a-context \
--kubeconfig ~/.kube/config
# Enable cross-cluster service discovery
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: service-a
namespace: default
spec:
host: service-a.cluster-a.svc.cluster.local
trafficPolicy:
connectionPool:
tcp:
maxConnections: 100
loadBalancer:
consistentHash:
httpHeaderName: "x-user-id"
tls:
mode: ISTIO_MUTUAL
# Linkerd Multi-Cluster
linkerd mc link --destination-context cluster-b --target-ns default | kubectl apply -f -
linkerd mc gateway --context cluster-b
linkerd mc check
Managing multiple clusters requires specialized tools for visibility, operations, and governance.
ArgoCD
GCP Anthos
Rancher
OPA/Gatekeeper
# ArgoCD multi-cluster configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
clusters: |
- name: cluster-a
server: https://cluster-a-api.example.com
config:
tlsClientConfig:
caData:
namespaces:
- default
- production
- name: cluster-b
server: https://cluster-b-api.example.com
config:
bearerToken:
namespaces:
- default
- production
# ApplicationSet with cluster generator
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: nginx-multi-cluster
spec:
generators:
- clusters:
selector:
matchLabels:
environment: production
template:
metadata:
name: '{{name}}-nginx'
spec:
project: default
source:
repoURL: https://github.com/myorg/apps
targetRevision: HEAD
path: ./nginx
destination:
server: '{{server}}'
namespace: default
| Approach | Use Case | Complexity | Latency | Security |
|---|---|---|---|---|
| Federation (kubefed) | Unified API, cross-cluster resources | High | Medium | Medium |
| Service Mesh | Service-to-service networking, security | High | Low | High |
| VPN/Tunneling | Secure cross-cluster connectivity | Medium | Medium | High |
| Cloud Networking | High-bandwidth VPC peering | Low | Low | Medium |
| GitOps (ArgoCD) | Deployment management, consistency | Medium | N/A | High |
| Global Load Balancing | Traffic routing, failover | Medium | Low | Medium |
Multi-cluster architecture is essential for enterprise-grade Kubernetes deployments. Start with clear use cases, choose the right patterns for your needs, and invest in automation and observability for successful multi-cluster operations.