podAntiAffinity主要实现以运行的pod为参照,让新创建的pod不在一个区域中的功能,它的配置方式和选项跟podAffinity是一样的。
1)继续使用上个案例中的目标pod,pod-podaffinity-target.yaml
2)创建pod-podantiaffinity-required.yaml,内容如下
apiVersion: v1
kind: Pod
metadata:
name: pod-podantiaffinity-required
namespace: dev
spec:
containers:
- name: nginx
image: nginx:1.17.1
affinity: #亲和性设置
podAntiAffinity: #设置pod反亲和性
requiredDuringSchedulingIgnoredDuringExecution: #硬限制
- labelSelector:
matchExpressions: #匹配env的值["pro","yyy"]中的标签
- key: podenv
operator: In
values: ["pro","yyy"]
topologyKey: kubernetes.io/hostnmae
#创建pod
kubectl create -f pod-podantiaffinity-required.yaml
#查看pod信息
kubectl get pods pod-podantiaffinity-required -n dev -o wide
[root@master k8s]# kubectl get pods pod-podantiaffinity-required -n dev -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-podantiaffinity-required 1/1 Running 0 27s 10.244.2.14 node2 <none> <none>
注意:非原创,是跟着黑马视频学习一个字一个字敲出来的笔记
视频地址:
https://www.bilibili.com/video/BV1xX4y1K7nb?p=2
本文暂时没有评论,来添加一个吧(●'◡'●)