首页 > 编程语言 >nodeAffinity

nodeAffinity

时间:2023-01-05 20:32:00浏览次数:44  
标签:node kubectl root k8smaster4 pod ns nodeAffinity

查看路径
[root@k8smaster4 ns]# kubectl explain pod.spec.affinity
Affinity类别
nodeAffinity
podAffinity
podAntiAffinity
编写Yaml文件
[root@k8smaster4 ns]# cat pod-nodeAffinity-demo.yaml 
apiVersion: v1
kind: Pod
metadata:
name: pod-node-affinity-demo
namespace: default
labels:
app: myapp
tier: frontend
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: zon
operator: In
values:
- foo
- bar
containers:
- name: myapp
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
查看Pod信息
[root@k8smaster4 ns]# kubectl describe pod pod-node-affinity-demo
node添加标签
[root@k8smaster4 ns]# kubectl label node k8snode5 zon=foo
查看node标签
[root@k8smaster4 ns]# kubectl get nodes --show-labels
查看某一个node标签
[root@k8smaster4 ns]# kubectl get node k8snode5 --show-labels
删除某个node标签
[root@k8smaster4 ns]# kubectl label node k8snode5 zon-
软亲和性Yaml

[root@k8smaster4 ns]# cat prefer-nodeAffinity-demo.yaml 
apiVersion: v1
kind: Pod
metadata:
name: pod-preference-affinity-demo
namespace: default
labels:
app: test
mysql: test
spec:
containers:
- name: myapp
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: zone1
operator: In
values:
- foo1
- bar1
weight: 10
- preference:
matchExpressions:
- key: zone2
operator: In
values:
- foo2
- bar2
weight: 20

标签:node,kubectl,root,k8smaster4,pod,ns,nodeAffinity
From: https://blog.51cto.com/u_11726705/5991839

相关文章