Kubernetes Multi-Cluster Management
Best practices for managing multiple Kubernetes clusters effectively
Kubernetes Multi-Cluster Management
Managing multiple Kubernetes clusters requires careful planning and proper tooling. This guide covers essential practices for multi-cluster management.
Video Tutorial
Learn more about Kubernetes multi-cluster management in this comprehensive video tutorial:
Prerequisites
- Basic understanding of Kubernetes
- Access to multiple Kubernetes clusters
- kubectl CLI tool installed
- Familiarity with cluster management tools
Project Structure
.
├── multi-cluster/
│ ├── fleet/ # Fleet management configs
│ ├── kubefed/ # KubeFed configurations
│ ├── policies/ # Policy configurations
│ └── networking/ # Cross-cluster networking
└── monitoring/
├── metrics/ # Multi-cluster metrics
└── alerts/ # Alert configurations
Fleet Management
1. Rancher Fleet Configuration
apiVersion: fleet.cattle.io/v1alpha1
kind: GitRepo
metadata:
name: app-deployment
namespace: fleet-default
spec:
repo: https://github.com/org/app-deployments
branch: main
paths:
- manifests
targets:
- name: production
clusterSelector:
matchLabels:
env: prod
2. Cluster Group Definition
apiVersion: fleet.cattle.io/v1alpha1
kind: ClusterGroup
metadata:
name: production-clusters
namespace: fleet-default
spec:
selector:
matchLabels:
env: prod
Federation Configuration
1. KubeFed Setup
apiVersion: core.kubefed.io/v1beta1
kind: KubeFedConfig
metadata:
name: kubefed
namespace: kube-federation-system
spec:
scope: Namespaced
controllerDuration:
availableDelay: 20s
unavailableDelay: 60s
2. Federated Deployment
apiVersion: types.kubefed.io/v1beta1
kind: FederatedDeployment
metadata:
name: federated-app
namespace: default
spec:
template:
metadata:
labels:
app: federated-app
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:latest
placement:
clusters:
- name: cluster1
- name: cluster2
Cross-Cluster Networking
1. Service Mesh Configuration
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: cross-cluster-service
spec:
hosts:
- app.global
location: MESH_INTERNAL
ports:
- number: 80
name: http
protocol: HTTP
resolution: DNS
endpoints:
- address: app.cluster1.global
ports:
http: 80
- address: app.cluster2.global
ports:
http: 80
2. Multi-Cluster Ingress
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: global-ingress
spec:
controller: example.com/ingress-controller
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: global-ingress
annotations:
kubernetes.io/ingress.class: global-ingress
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app
port:
number: 80
Policy Management
1. Cluster Policy
apiVersion: policy.karmada.io/v1alpha1
kind: ClusterPropagationPolicy
metadata:
name: default-policy
spec:
resourceSelectors:
- apiVersion: apps/v1
kind: Deployment
placement:
clusterAffinity:
clusterNames:
- cluster1
- cluster2
2. Resource Quotas
apiVersion: v1
kind: ResourceQuota
metadata:
name: multi-cluster-quota
spec:
hard:
requests.cpu: "20"
requests.memory: 100Gi
limits.cpu: "40"
limits.memory: 200Gi
Monitoring Setup
1. Multi-Cluster Prometheus
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: multi-cluster-prometheus
spec:
replicas: 2
serviceMonitorSelector:
matchLabels:
cluster: monitored
additionalScrapeConfigs:
name: additional-scrape-configs
key: prometheus-additional.yaml
2. Alert Configuration
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: multi-cluster-alerts
spec:
groups:
- name: multi-cluster
rules:
- alert: ClusterUnreachable
expr: up{job="kube-apiserver"} == 0
for: 5m
labels:
severity: critical
Best Practices Checklist
- Implement fleet management
- Configure federation
- Set up cross-cluster networking
- Implement policies
- Configure monitoring
- Set up alerts
- Resource management
- Security policies
- Backup strategies
- Disaster recovery
Multi-Cluster Patterns
Active-Active
- Load balancing across clusters
- Global service discovery
- Consistent data replication
- Automated failover
Active-Passive
- Standby clusters
- Regular data sync
- Disaster recovery
- Manual failover
Hybrid Deployment
- Mixed cloud providers
- Regional distribution
- Cost optimization
- Compliance requirements
Common Pitfalls
- Inconsistent configurations
- Poor network connectivity
- Inadequate monitoring
- Security gaps
- Resource conflicts
Management Tools
1. Cluster API
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: new-cluster
spec:
clusterNetwork:
pods:
cidrBlocks: ["192.168.0.0/16"]
services:
cidrBlocks: ["10.96.0.0/12"]
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSCluster
name: new-cluster
2. GitOps Configuration
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: multi-cluster-app
spec:
project: default
source:
repoURL: https://github.com/org/multi-cluster-apps.git
targetRevision: HEAD
path: apps
destination:
server: https://kubernetes.default.svc
namespace: default
Conclusion
Implementing these multi-cluster management practices ensures efficient operation of distributed Kubernetes environments. Regular monitoring and maintenance are essential for optimal performance.