创建pod,requiredDuringSchedulingIgnoredDuringExecution参数表示:节点必须包含一个键名为 kubernetes.io/hostname
的标签, 并且该标签的取值必须为 k8scloude4
或 k8scloude5
。
[root@k8scloude1 pod]# vim requiredDuringSchedule1.yaml [root@k8scloude1 pod]# cat requiredDuringSchedule1.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod1name: pod1namespace: podspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues:- k8scloude4- k8scloude5containers:- image: nginximagePullPolicy: IfNotPresentname: pod1resources: {}ports:- name: httpcontainerPort: 80protocol: TCPhostPort: 80dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# kubectl apply -f requiredDuringSchedule1.yamlpod/pod1 created
由于requiredDuringSchedulingIgnoredDuringExecution是硬策略,k8scloude4,k8scloude5不满足条件,所以pod创建失败
[root@k8scloude1 pod]# kubectl get pods -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod10/1Pending07s<none><none><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
3.5.2 使用软策略preferredDuringSchedulingIgnoredDuringExecution给节点打标签
[root@k8scloude1 pod]# kubectl label nodes k8scloude2 xx=72node/k8scloude2 labeled[root@k8scloude1 pod]# kubectl label nodes k8scloude3 xx=59node/k8scloude3 labeled
创建pod,preferredDuringSchedulingIgnoredDuringExecution参数表示:节点最好具有一个键名为 xx
且取值大于 60
的标签 。
[root@k8scloude1 pod]# vim preferredDuringSchedule.yaml [root@k8scloude1 pod]# cat preferredDuringSchedule.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod1name: pod1namespace: podspec:affinity:nodeAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 2preference:matchExpressions:- key: xxoperator: Gtvalues:- "60"containers:- image: nginximagePullPolicy: IfNotPresentname: pod1resources: {}ports:- name: httpcontainerPort: 80protocol: TCPhostPort: 80dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# kubectl apply -f preferredDuringSchedule.yamlpod/pod1 created
可以看到pod运行在k8scloude2,因为k8scloude2标签为 xx=72,72大于60
[root@k8scloude1 pod]# kubectl get pods -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod11/1Running013s10.244.112.159k8scloude2<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
创建pod,preferredDuringSchedulingIgnoredDuringExecution参数表示:节点最好具有一个键名为 xx
且取值大于 600
的标签 。
[root@k8scloude1 pod]# vim preferredDuringSchedule1.yaml [root@k8scloude1 pod]# cat preferredDuringSchedule1.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod1name: pod1namespace: podspec:affinity:nodeAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 2preference:matchExpressions:- key: xxoperator: Gtvalues:- "600"containers:- image: nginximagePullPolicy: IfNotPresentname: pod1resources: {}ports:- name: httpcontainerPort: 80protocol: TCPhostPort: 80dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# kubectl apply -f preferredDuringSchedule1.yamlpod/pod1 created
因为preferredDuringSchedulingIgnoredDuringExecution是软策略,尽管k8scloude2,k8scloude3都不满足xx>600,但是还是能成功创建pod
经验总结扩展阅读
- 多情总被无情伤 这些星座是爱情里的傻瓜
- JAVA的File对象
- 秋天冰箱的温度怎么调才正确 冰箱不制冷的原因是什么
- 性格坚强的三大星座女 却最让人心疼
- 外出发展 最易发财的星座
- 画饼专家 这些星座男的话不能全信
- 2023年9月13日是剪指甲吉日吗 2023年9月13日是剪指甲的黄道吉日吗
- 工资过10万的十大职业 哪些工作工资超高
- 2023年9月13日是年前洗澡的黄道吉日吗 2023年农历七月廿九年前洗澡吉日
- 十二星座秉承单身主义的原因 遇不到对的人还是享受孤独