Aller au contenu principal

Kubernetes Multi-Cloud


1 - Approches Multi-Cluster

1.1 Patterns

PatternAvantagesInconvénients
FederationAbstraction native K8sComplexe, moins mature
Service MeshTraffic managementOverhead réseau
GitOpsSimple, déclaratifPas de routing cross-cluster

2 - Service Mesh avec Istio

2.1 Architecture Multi-Cluster

2.2 Installation Istio Multi-Cluster

# Cluster 1 (AWS)
istioctl install --set profile=default \
--set values.global.meshID=mesh1 \
--set values.global.multiCluster.clusterName=cluster1 \
--set values.global.network=network1

# Créer le remote secret pour cluster 2
istioctl x create-remote-secret --name=cluster1 > cluster1-secret.yaml

# Cluster 2 (Azure) - Appliquer le secret
kubectl apply -f cluster1-secret.yaml

# Cluster 2 - Installation
istioctl install --set profile=default \
--set values.global.meshID=mesh1 \
--set values.global.multiCluster.clusterName=cluster2 \
--set values.global.network=network2

2.3 Service Entry Cross-Cluster

# Exposer un service du cluster 1 au cluster 2
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
name: external-api
spec:
hosts:
- api.cluster1.local
location: MESH_INTERNAL
ports:
- number: 80
name: http
protocol: HTTP
resolution: DNS
endpoints:
- address: api.cluster1.example.com
ports:
http: 80

3 - GitOps Multi-Cluster avec ArgoCD

3.1 Architecture

3.2 Ajouter des clusters à ArgoCD

# Ajouter le cluster AWS
argocd cluster add aws-eks-production --name aws-prod

# Ajouter le cluster Azure
argocd cluster add azure-aks-production --name azure-prod

# Ajouter le cluster GCP
argocd cluster add gcp-gke-production --name gcp-prod

# Lister les clusters
argocd cluster list

3.3 ApplicationSet Multi-Cluster

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: my-app-multicloud
namespace: argocd
spec:
generators:
- list:
elements:
- cluster: aws-prod
url: https://eks.aws.example.com
region: eu-west-1
- cluster: azure-prod
url: https://aks.azure.example.com
region: westeurope
- cluster: gcp-prod
url: https://gke.gcp.example.com
region: europe-west1
template:
metadata:
name: 'my-app-{{cluster}}'
spec:
project: default
source:
repoURL: https://github.com/myorg/my-app.git
targetRevision: main
path: 'kubernetes/overlays/{{cluster}}'
destination:
server: '{{url}}'
namespace: my-app
syncPolicy:
automated:
prune: true
selfHeal: true

4 - Rancher Multi-Cluster

4.1 Installation

# Installer Rancher avec Helm
helm repo add rancher-latest https://releases.rancher.com/server-charts/latest

helm install rancher rancher-latest/rancher \
--namespace cattle-system \
--create-namespace \
--set hostname=rancher.example.com \
--set replicas=3

4.2 Import de clusters

# Via l'interface Rancher:
# 1. Cluster Management > Import Existing
# 2. Générer la commande kubectl
# 3. Exécuter sur le cluster cible

# Exemple de commande générée
kubectl apply -f https://rancher.example.com/v3/import/xxxxx.yaml

4.3 Fleet pour GitOps

# fleet.yaml
defaultNamespace: my-app
helm:
releaseName: my-app
chart: ./charts/my-app
values:
replicaCount: 3

targetCustomizations:
- name: aws-production
clusterSelector:
matchLabels:
env: production
cloud: aws
helm:
values:
replicaCount: 5

- name: azure-dr
clusterSelector:
matchLabels:
env: dr
cloud: azure
helm:
values:
replicaCount: 2

5 - Karmada Federation

5.1 Architecture

5.2 PropagationPolicy

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
name: my-app-propagation
spec:
resourceSelectors:
- apiVersion: apps/v1
kind: Deployment
name: my-app
placement:
clusterAffinity:
clusterNames:
- aws-cluster
- azure-cluster
replicaScheduling:
replicaDivisionPreference: Weighted
replicaSchedulingType: Divided
weightPreference:
staticWeightList:
- targetCluster:
clusterNames:
- aws-cluster
weight: 2
- targetCluster:
clusterNames:
- azure-cluster
weight: 1

6 - Traffic Global avec Submariner

6.1 Connecter les clusters

# Installer Submariner sur chaque cluster
subctl deploy-broker --kubeconfig /path/to/management/config

# Joindre les clusters
subctl join broker-info.subm --kubeconfig /path/to/aws-cluster \
--clusterid aws-cluster

subctl join broker-info.subm --kubeconfig /path/to/azure-cluster \
--clusterid azure-cluster

6.2 ServiceExport

# Exporter un service pour le rendre accessible cross-cluster
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceExport
metadata:
name: my-service
namespace: my-app

6.3 ServiceImport

# Importer un service d'un autre cluster
apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ServiceImport
metadata:
name: my-service
namespace: my-app
spec:
type: ClusterSetIP
ports:
- port: 80
protocol: TCP

7 - Configuration kubectl Multi-Context

# Voir les contextes
kubectl config get-contexts

# Changer de contexte
kubectl config use-context aws-production

# Utiliser un contexte spécifique
kubectl --context=azure-dr get pods

# kubectx pour faciliter
kubectx aws-production

# Alias utiles dans .bashrc
alias kaws='kubectl --context=aws-production'
alias kazure='kubectl --context=azure-dr'
alias kgcp='kubectl --context=gcp-analytics'

Résumé

Dans ce chapitre, nous avons appris :

  • Les approches multi-cluster
  • Istio Service Mesh multi-cluster
  • ArgoCD GitOps multi-cluster
  • Rancher et Fleet
  • Karmada Federation
  • Submariner pour le networking

Prochaine étape

Dans le prochain chapitre, nous verrons le Networking Multi-Cloud.

→ Chapitre suivant : Networking Multi-Cloud


← Retour à la table des matières