Pod 拓扑分布约束
1.环境
-
CentOS Linux release 8.3.2011
-
kubernetes 1.18.16
-
一个master节点,两个node节点
2 使用Pod 拓扑分布约束
2.1 在api-server和scheduler中开启EvenPodsSpread
编辑/etc/kubernetes/manifests/kube-apiserver.yaml
#在文件中添加
- --feature-gates=EvenPodsSpread=true
编辑/etc/kubernetes/manifests/kube-scheduler.yaml
#在文件中添加
- --feature-gates=EvenPodsSpread=true
2.2给节点添加label
kuebctl label nodes node01 node=node1
kubectl label nodes node02 node=node2
kubectl label nodes master node=master
2.3 创建带拓扑约束的deployment
2.3.1 whenUnsatisfiable: DoNotSchedule 情况
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
foo: bar
spec:
replicas: 8
selector:
matchLabels:
foo: bar
template:
metadata:
labels:
foo: bar
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: node #以node为key
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
foo: bar
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
分布结果
[root@master ~]# kubectl get pods -A -owide |grep test
default test-69fcfbdb9d-5vtc6 1/1 Running 0 5m50s 10.244.0.4 master <none> <none>
default test-69fcfbdb9d-8xr72 1/1 Running 0 5s 10.244.0.6 master <none> <none>
default test-69fcfbdb9d-gkmpw 1/1 Running 0 5s 10.244.1.5 node01 <none> <none>
default test-69fcfbdb9d-hkkpx 1/1 Running 0 5s 10.244.1.6 node01 <none> <none>
default test-69fcfbdb9d-qgfpc 1/1 Running 0 5s 10.244.2.10 node02 <none> <none>
default test-69fcfbdb9d-rpvhw 1/1 Running 0 5m50s 10.244.0.5 master <none

本文介绍了在Kubernetes环境中如何设置Pod的拓扑分布约束,包括在api-server和scheduler中启用EvenPodsSpread,给节点添加label,以及创建带有不同`whenUnsatisfiable`策略的Deployment。通过实例展示了`DoNotSchedule`和`ScheduleAnyway`两种情况下的Pod分布效果,揭示了当节点Pod数量达到上限时,新Pod的调度行为。
最低0.47元/天 解锁文章
867

被折叠的 条评论
为什么被折叠?



