节点选择器 nodeSelector
- 节点选择器 通过匹配一个 节点的Label键值对告诉kube scheduler 将pod调度到哪个节点
kubectl lable node mynode zzz=xxx #给mynode节点添加 zzz=xxx标签
apiVersion: v1
kind: Pod
metadata:
name: app01
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- name: redisport
containerPort: 6379
protocol: TCP
nodeSelector:
zzz: xxx
节点亲和力和反亲和力 Node Affinity and Anti-Affinity
- 如果 nodeSelector 与节点上的标签不匹配,则不会调度 pod。Node Affinity and Anti-Affinity
- spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution
-
Soft NodeAffinity 和 Anti-Affinity:如果节点标签存在,Pod 将在那里运行。如果没有,那么 Pod 将被重新调度到集群内的其他地方。
- spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution
-
Hard NodeAffinity 和 Anti-Affinity:如果节点标签不存在,则根本不会调度 Pod。
k8s节点分配nodeSelector, Affinity和Anti-Affinity 亲和性和反亲和性