Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy and manage Kubernetes workloads: manifests, RBAC, Helm charts, service mesh, GitOps, and troubleshooting.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/multi-cluster.md
1# Multi-Cluster Management23---45## Cluster API67### Installation89```bash10# Install clusterctl CLI11curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.0/clusterctl-linux-amd64 -o clusterctl12chmod +x clusterctl && sudo mv clusterctl /usr/local/bin/1314# Initialize management cluster with AWS provider15clusterctl init --infrastructure aws1617# Initialize with multiple providers18clusterctl init \19--infrastructure aws,azure \20--control-plane kubeadm \21--bootstrap kubeadm22```2324### Cluster Definition2526```yaml27apiVersion: cluster.x-k8s.io/v1beta128kind: Cluster29metadata:30name: production-cluster31namespace: clusters32spec:33clusterNetwork:34pods:35cidrBlocks: ["192.168.0.0/16"]36services:37cidrBlocks: ["10.96.0.0/12"]38controlPlaneRef:39apiVersion: controlplane.cluster.x-k8s.io/v1beta140kind: KubeadmControlPlane41name: production-control-plane42infrastructureRef:43apiVersion: infrastructure.cluster.x-k8s.io/v1beta244kind: AWSCluster45name: production-cluster46---47apiVersion: infrastructure.cluster.x-k8s.io/v1beta248kind: AWSCluster49metadata:50name: production-cluster51namespace: clusters52spec:53region: us-west-254sshKeyName: production-key55network:56vpc:57cidrBlock: 10.0.0.0/1658subnets:59- availabilityZone: us-west-2a60cidrBlock: 10.0.1.0/2461isPublic: true62- availabilityZone: us-west-2b63cidrBlock: 10.0.2.0/2464isPublic: true65```6667### Control Plane6869```yaml70apiVersion: controlplane.cluster.x-k8s.io/v1beta171kind: KubeadmControlPlane72metadata:73name: production-control-plane74namespace: clusters75spec:76replicas: 377version: v1.28.078machineTemplate:79infrastructureRef:80apiVersion: infrastructure.cluster.x-k8s.io/v1beta281kind: AWSMachineTemplate82name: production-control-plane83kubeadmConfigSpec:84clusterConfiguration:85apiServer:86extraArgs:87cloud-provider: aws88controllerManager:89extraArgs:90cloud-provider: aws91initConfiguration:92nodeRegistration:93kubeletExtraArgs:94cloud-provider: aws95joinConfiguration:96nodeRegistration:97kubeletExtraArgs:98cloud-provider: aws99```100101### Machine Deployment (Worker Nodes)102103```yaml104apiVersion: cluster.x-k8s.io/v1beta1105kind: MachineDeployment106metadata:107name: production-workers108namespace: clusters109spec:110clusterName: production-cluster111replicas: 5112selector:113matchLabels:114cluster.x-k8s.io/cluster-name: production-cluster115template:116spec:117clusterName: production-cluster118version: v1.28.0119bootstrap:120configRef:121apiVersion: bootstrap.cluster.x-k8s.io/v1beta1122kind: KubeadmConfigTemplate123name: production-workers124infrastructureRef:125apiVersion: infrastructure.cluster.x-k8s.io/v1beta2126kind: AWSMachineTemplate127name: production-workers128---129apiVersion: infrastructure.cluster.x-k8s.io/v1beta2130kind: AWSMachineTemplate131metadata:132name: production-workers133namespace: clusters134spec:135template:136spec:137instanceType: m5.xlarge138iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io139sshKeyName: production-key140rootVolume:141size: 100142type: gp3143```144145## Cross-Cluster Networking146147### Submariner Installation148149```bash150# Install subctl151curl -Ls https://get.submariner.io | bash152153# Join clusters to broker154subctl deploy-broker --kubeconfig kubeconfig-cluster1155156# Join workload clusters157subctl join --kubeconfig kubeconfig-cluster1 broker-info.subm --clusterid cluster1158subctl join --kubeconfig kubeconfig-cluster2 broker-info.subm --clusterid cluster2159160# Verify connectivity161subctl show all162```163164### ServiceExport/ServiceImport165166```yaml167# Export service from cluster1168apiVersion: multicluster.x-k8s.io/v1alpha1169kind: ServiceExport170metadata:171name: myapp172namespace: production173---174# Service is auto-imported to other clusters as:175# myapp.production.svc.clusterset.local176```177178### Cilium Cluster Mesh179180```bash181# Enable cluster mesh on both clusters182cilium clustermesh enable --context cluster1183cilium clustermesh enable --context cluster2184185# Connect clusters186cilium clustermesh connect --context cluster1 --destination-context cluster2187188# Verify189cilium clustermesh status --context cluster1190```191192```yaml193# Global service accessible from all clusters194apiVersion: v1195kind: Service196metadata:197name: myapp198namespace: production199annotations:200service.cilium.io/global: "true"201spec:202type: ClusterIP203selector:204app: myapp205ports:206- port: 80207```208209## Multi-Cluster DNS210211### ExternalDNS with Route53212213```yaml214apiVersion: apps/v1215kind: Deployment216metadata:217name: external-dns218namespace: kube-system219spec:220template:221spec:222containers:223- name: external-dns224image: k8s.gcr.io/external-dns/external-dns:v0.14.0225args:226- --source=service227- --source=ingress228- --provider=aws229- --aws-zone-type=public230- --registry=txt231- --txt-owner-id=my-cluster232- --domain-filter=example.com233```234235### CoreDNS Federation236237```yaml238# Forward queries for other clusters239apiVersion: v1240kind: ConfigMap241metadata:242name: coredns243namespace: kube-system244data:245Corefile: |246.:53 {247errors248health249kubernetes cluster.local in-addr.arpa ip6.arpa {250pods insecure251fallthrough in-addr.arpa ip6.arpa252}253# Forward to cluster2 DNS254cluster2.local:53 {255forward . 10.0.0.10256}257forward . /etc/resolv.conf258cache 30259loop260reload261loadbalance262}263```264265## Workload Distribution266267### Kubernetes Federation v2268269```yaml270apiVersion: types.kubefed.io/v1beta1271kind: FederatedDeployment272metadata:273name: myapp274namespace: production275spec:276template:277metadata:278labels:279app: myapp280spec:281replicas: 3282selector:283matchLabels:284app: myapp285template:286metadata:287labels:288app: myapp289spec:290containers:291- name: myapp292image: myregistry.io/myapp:v1.0.0293placement:294clusters:295- name: cluster-us-west296- name: cluster-us-east297- name: cluster-eu-west298overrides:299- clusterName: cluster-us-west300clusterOverrides:301- path: "/spec/replicas"302value: 5303- clusterName: cluster-eu-west304clusterOverrides:305- path: "/spec/replicas"306value: 3307```308309### ArgoCD Multi-Cluster310311```yaml312apiVersion: argoproj.io/v1alpha1313kind: ApplicationSet314metadata:315name: myapp-global316namespace: argocd317spec:318generators:319- clusters:320selector:321matchLabels:322environment: production323template:324metadata:325name: 'myapp-{{name}}'326spec:327project: default328source:329repoURL: https://github.com/myorg/myapp-manifests.git330targetRevision: main331path: overlays/production332destination:333server: '{{server}}'334namespace: production335syncPolicy:336automated:337prune: true338selfHeal: true339```340341## Disaster Recovery342343### Velero Backup Configuration344345```bash346# Install Velero with S3347velero install \348--provider aws \349--plugins velero/velero-plugin-for-aws:v1.8.0 \350--bucket velero-backups \351--backup-location-config region=us-west-2 \352--snapshot-location-config region=us-west-2 \353--secret-file ./credentials-velero354```355356```yaml357# Scheduled backup358apiVersion: velero.io/v1359kind: Schedule360metadata:361name: daily-backup362namespace: velero363spec:364schedule: "0 2 * * *"365template:366includedNamespaces:367- production368- staging369excludedResources:370- events371storageLocation: default372volumeSnapshotLocations:373- default374ttl: 720h # 30 days375---376# Restore to different cluster377apiVersion: velero.io/v1378kind: Restore379metadata:380name: restore-production381namespace: velero382spec:383backupName: daily-backup-20240115384includedNamespaces:385- production386restorePVs: true387preserveNodePorts: true388```389390### Active-Passive Failover391392```yaml393# Primary cluster ingress394apiVersion: networking.k8s.io/v1395kind: Ingress396metadata:397name: myapp398annotations:399external-dns.alpha.kubernetes.io/hostname: myapp.example.com400external-dns.alpha.kubernetes.io/set-identifier: primary401external-dns.alpha.kubernetes.io/aws-weight: "100"402spec:403rules:404- host: myapp.example.com405http:406paths:407- path: /408pathType: Prefix409backend:410service:411name: myapp412port:413number: 80414---415# Secondary cluster ingress416apiVersion: networking.k8s.io/v1417kind: Ingress418metadata:419name: myapp420annotations:421external-dns.alpha.kubernetes.io/hostname: myapp.example.com422external-dns.alpha.kubernetes.io/set-identifier: secondary423external-dns.alpha.kubernetes.io/aws-weight: "0"424spec:425rules:426- host: myapp.example.com427# ... same backend config428```429430## Centralized Management Tools431432### Rancher Setup433434```bash435# Install Rancher with Helm436helm repo add rancher-stable https://releases.rancher.com/server-charts/stable437helm install rancher rancher-stable/rancher \438--namespace cattle-system \439--create-namespace \440--set hostname=rancher.example.com \441--set bootstrapPassword=admin442```443444### Kubeconfig Management445446```yaml447# Merge multiple kubeconfigs448# ~/.kube/config449apiVersion: v1450kind: Config451clusters:452- name: cluster-us-west453cluster:454server: https://cluster-us-west.example.com455certificate-authority-data: ...456- name: cluster-us-east457cluster:458server: https://cluster-us-east.example.com459certificate-authority-data: ...460contexts:461- name: us-west462context:463cluster: cluster-us-west464user: admin-us-west465namespace: default466- name: us-east467context:468cluster: cluster-us-east469user: admin-us-east470namespace: default471users:472- name: admin-us-west473user:474token: ...475- name: admin-us-east476user:477token: ...478current-context: us-west479```480481```bash482# Switch between clusters483kubectl config use-context us-west484kubectl config use-context us-east485486# Run command against specific cluster487kubectl --context=us-west get pods488kubectl --context=us-east get pods489490# Use kubectx for easier switching491kubectx us-west492```493494## Best Practices4954961. **Use Cluster API** for declarative cluster lifecycle management4972. **Implement service mesh** for secure cross-cluster communication4983. **Set up DNS-based routing** for global service discovery4994. **Configure automated backups** with Velero across clusters5005. **Use GitOps** (ArgoCD/Flux) for consistent multi-cluster deployments5016. **Implement network policies** consistently across clusters5027. **Centralize observability** with cross-cluster metrics and logs5038. **Test failover procedures** regularly5049. **Use namespaces consistently** across clusters50510. **Document cluster topology** and dependencies50611. **Implement RBAC** with cross-cluster access patterns50712. **Monitor cluster health** from centralized dashboard508