k8s的Pod反亲和性
针对对象为Pod,目的是实现,新建Pod和目标Pod不要调度到一起,不在同一个Node上
示例:
root@k8s-master:/home/vagrant# cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: testpod01
labels:
app: myapp01
env: test1
spec:
containers:
- name: testpod01
image: nginx:1.23.2
imagePullPolicy: IfNotPresent
root@k8s-master:/home/vagrant# cat pod2.yaml
apiVersion: v1
kind: Pod
metadata:
name: testpod02
labels:
app: myapp02
env: test2
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution: ##必须满足下面匹配规则
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapp01 ## app=myapp01, 上面的Pod是符合要求的
topologyKey: "kubernetes.io/hostname"
containers:
- name: testpod02
image: redis:6.2
root@k8s-master:/home/vagrant# kubectl create -f pod.yaml
pod/testpod01 created
root@k8s-master:/home/vagrant# kubectl create -f pod2.yaml
pod/testpod02 created
root@k8s-master:/home/vagrant# kubectl get pods -o wide --show-labels
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
node-affinity 1/1 Running 0 30m 172.16.126.2 k8s-worker2 <none> <none> <none>
testpod01 1/1 Running 0 11s 172.16.194.67 k8s-worker1 <none> <none> app=myapp01,env=test1
testpod02 1/1 Running 0 9s 172.16.126.3 k8s-worker2 <none> <none> app=myapp02,env=test2
原文地址:https://blog.csdn.net/weixin_65562581/article/details/144387706
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!