- A+
所属分类:K8S
位置:deploy.spec.template.spec.affinity
硬亲和和软亲和说明:(不管是node还是pod都可以用软亲和或者硬亲和)
- requiredDuringSchedulingIgnoredDuringExecution(硬亲和):必须满足,如果不满足则不进行调度
- preferredDuringSchedulingIgnoredDuringExecution(软亲和):倾向满足,不满足的情况下会调度的不符合条件的Node上。
Node亲和性:
nodeAffinity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
apiVersion: v1 kind: Pod metadata: name: nginx spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: #硬亲和 nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name #NODE的key operator: In #在 values: #值里面 - e2e-az1 - e2e-az2 preferredDuringSchedulingIgnoredDuringExecution:#软亲和 - weight: 1 //取值范围1-100 preference: matchExpressions: - key: another-node-label-key operator: In values: - another-node-label-value containers: - name: nginx image: docker.io/nginx |
Pod亲和性:
podAffinity:pod和pod运行在一起
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
apiVersion: v1 kind: Pod metadata: name: with-pod-affinity spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: #硬亲和,必须满足 - labelSelector: #pod标签选择器 matchExpressions: - key: security #key operator: In #在 values: - S1 #value的列表 topologyKey: kubernetes.io/hostname #通过node的hostname判断是否是相同节点,节点名一定不能一样 containers: - name: with-pod-affinity image: k8s.gcr.io/pause:2.0 |
podAntiAffinity: pod和pod不能在一起
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
apiVersion: v1 kind: Pod metadata: name: with-pod-affinity spec: affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: #软亲和 - weight: 100 #权重 podAffinityTerm: labelSelector: matchExpressions: - key: security operator: In values: - S2 #pod label security=s2,则不能调度 topologyKey: kubernetes.io/hostname #通过node的hostname判断是否是相同节点,节点名一定不能一样 containers: - name: with-pod-affinity image: k8s.gcr.io/pause:2.0 |
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫