Karmada部署与使用体验
初始化 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 member2
kubectl karmada uninit
作者:wanghongwei
版权声明:本作品遵循<CC BY-NC-ND 4.0>版权协议,商业转载请联系作者获得授权,非商业转载请附上原文出处链接及本声明。