初始化 karmada 控制平面
kubectl krew install karmada
kubectl karmada init --kube-image-registry='registry.cn-hangzhou.aliyuncs.com/google_containers'
查看 karmada 控制平面创建的资源
kubectl get deployments -n karmada-system
kubectl get statefulsets -n karmada-system
将 karmada 控制平面增加到当前主机的 kubeconfig 认证上下文中并切换到 karmada 控制平面
kubecm add -f /etc/karmada/karmada-apiserver.config
kubectl ctx karmada-apiserver
将 Kubernetes 集群注册到 Karmada 控制平面
kubectl karmada join member1 --cluster-kubeconfig=$HOME/.kube/config --cluster-context='kubernetes-admin@kubernetes'
kubectl karmada join member2 --cluster-kubeconfig=$HOME/.kube/config --cluster-context='cluster2'
查看注册的集群
kubectl get clusters
准备应用 deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
将 yaml 应用到 karmada 控制面板
kubectl apply -f deployment.yaml
准备应用多集群部署传播策略 propagationpolicy.yaml
apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
name: nginx-propagation
spec:
resourceSelectors:
- apiVersion: apps/v1
kind: Deployment
name: nginx
placement:
clusterAffinity:
clusterNames:
- member1
- member2
replicaScheduling:
replicaDivisionPreference: Weighted
replicaSchedulingType: Divided
weightPreference:
staticWeightList:
- targetCluster:
clusterNames:
- member1
weight: 1
- targetCluster:
clusterNames:
- member2
weight: 1
将 yaml 应用到 karmada 控制面板
kubectl apply -f propagationpolicy.yaml
联邦注销与清理
kubectl karmada unjoin member1
kubectl karmada unjoin member1
kubectl karmada uninit
标签:kubectl,yaml,部署,nginx,member1,体验,--,Karmada,karmada
From: https://www.cnblogs.com/wanghongwei-dev/p/17534994.html