在上述类型中,IgnoredDuringExecution 意味着如果节点标签在 Kubernetes 调度 Pod 后发生了变更,Pod 仍将继续运行
。你可以使用 Pod 规约中的 .spec.affinity.nodeAffinity 字段来设置节点亲和性 。
查看nodeAffinity字段解释
[root@k8scloude1 pod]# kubectl explain pods.spec.affinity.nodeAffinityKIND:PodVERSION:v1RESOURCE: nodeAffinity <Object>DESCRIPTION:Describes node affinity scheduling rules for the pod.Node affinity is a group of node affinity scheduling rules.FIELDS:#软策略preferredDuringSchedulingIgnoredDuringExecution <[]Object>The scheduler will prefer to schedule pods to nodes that satisfy theaffinity expressions specified by this field, but it may choose a node thatviolates one or more of the expressions. The node that is most preferred isthe one with the greatest sum of weights, i.e. for each node that meets allof the scheduling requirements (resource request, requiredDuringSchedulingaffinity expressions, etc.), compute a sum by iterating through theelements of this field and adding "weight" to the sum if the node matchesthe corresponding matchExpressions; the node(s) with the highest sum arethe most preferred.#硬策略requiredDuringSchedulingIgnoredDuringExecution <Object>If the affinity requirements specified by this field are not met atscheduling time, the pod will not be scheduled onto the node. If theaffinity requirements specified by this field cease to be met at some pointduring pod execution (e.g. due to an update), the system may or may not tryto eventually evict the pod from its node.
3.5.1 使用硬策略requiredDuringSchedulingIgnoredDuringExecution创建pod,requiredDuringSchedulingIgnoredDuringExecution参数表示:节点必须包含一个键名为 kubernetes.io/hostname
的标签, 并且该标签的取值必须为 k8scloude2
或 k8scloude3
。你可以使用 operator 字段来为 Kubernetes 设置在解释规则时要使用的逻辑操作符 。你可以使用 In、NotIn、Exists、DoesNotExist、Gt 和 Lt 之一作为操作符 。NotIn 和 DoesNotExist 可用来实现节点反亲和性行为 。你也可以使用节点污点 将 Pod 从特定节点上驱逐 。
注意:
- 如果你同时指定了 nodeSelector 和 nodeAffinity,两者 必须都要满足, 才能将 Pod 调度到候选节点上 。
- 如果你指定了多个与 nodeAffinity 类型关联的 nodeSelectorTerms, 只要其中一个 nodeSelectorTerms 满足的话,Pod 就可以被调度到节点上 。
- 如果你指定了多个与同一 nodeSelectorTerms 关联的 matchExpressions, 则只有当所有 matchExpressions 都满足时 Pod 才可以被调度到节点上 。
[root@k8scloude1 pod]# vim requiredDuringSchedule.yaml#硬策略[root@k8scloude1 pod]# cat requiredDuringSchedule.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod1name: pod1namespace: podspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues:- k8scloude2- k8scloude3containers:- image: nginximagePullPolicy: IfNotPresentname: pod1resources: {}ports:- name: httpcontainerPort: 80protocol: TCPhostPort: 80dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# kubectl apply -f requiredDuringSchedule.yamlpod/pod1 created
可以看到pod运行在k8scloude3节点[root@k8scloude1 pod]# kubectl get podsNAMEREADYSTATUSRESTARTSAGEpod11/1Running06s[root@k8scloude1 pod]# kubectl get pods -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod11/1Running010s10.244.251.212k8scloude3<none><none>[root@k8scloude1 pod]# kubectl delete pod pod1 --forcewarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "pod1" force deleted
经验总结扩展阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 多情总被无情伤 这些星座是爱情里的傻瓜
- JAVA的File对象
- 秋天冰箱的温度怎么调才正确 冰箱不制冷的原因是什么
- 性格坚强的三大星座女 却最让人心疼
- 外出发展 最易发财的星座
- 画饼专家 这些星座男的话不能全信
- 2023年9月13日是剪指甲吉日吗 2023年9月13日是剪指甲的黄道吉日吗
- 工资过10万的十大职业 哪些工作工资超高
- 2023年9月13日是年前洗澡的黄道吉日吗 2023年农历七月廿九年前洗澡吉日
- 十二星座秉承单身主义的原因 遇不到对的人还是享受孤独