pod 反亲和测试验证
场景需求
node 节点上不允许有两个一样的pod,即每个节点上每个应用仅仅允许一个pod 运行
- 测试yaml
[root@k8sNode0 podqinhexing]# cat test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 4
template:
metadata:
labels:
app: nginx
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nginx
topologyKey: "kubernetes.io/hostname"
containers:
- name: nginx-server
image: nginx:latest
- 测试结果(第四个pod 显示pending 状态,即每个节点上落了一个pod)
[root@k8sNode0 podqinhexing]# kubectl get pod -o wide |grep nginx
nginx-78dfb97767-747w5 1/1 Running 0 8s 172.16.4.183 cn-zhangjiakou.172.16.4.39 <none> <none>
nginx-78dfb97767-bgl2n 1/1 Running 0 8s 172.16.4.243 cn-zhangjiakou.172.16.4.40 <none> <none>
nginx-78dfb97767-hrbrn 1/1 Running 0 8s 172.16.4.16 cn-zhangjiakou.172.16.4.38 <none> <none>
nginx-78dfb97767-qmjc9 0/1 Pending 0 8s <none> <none> <none> <none>
- 第四个pod 的报错日志
Warning FailedScheduling 15s default-scheduler 0/3 nodes are available: 3 node(s) didn't match pod anti-affinity rules. preemption: 0/3 nodes are available: 3 No preemption victims found for incoming pod.,