k8s 指定节点调度标签
nodeSelector 强制匹配指定pod 调度到标签 ssd[root@k8s-master cka3]# cat ssd.yamlapiVersion: v1kind: Podmetadata:name: nginx-kusc00401spec:containers:- name: nginximage: nginximagePullPolicy: IfNotPresentnodeSelec
·
nodeSelector 强制匹配
指定pod 调度到标签 ssd
[root@k8s-master cka3]# cat ssd.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-kusc00401
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disktype: ssd
这里显示亲和性不够
我们现在给节点加上标签:kubectl label nodes <node-name> <node-key>=<label-value>
[root@k8s-master cka3]# kubectl label nodes k8s-node2 disktype=ssd
node/k8s-node2 labeled
再次查看调度成功
-----------------------------------------------------------------------------------------------------------------------------
删除标签:
[root@k8s-master cka3]# kubectl label node k8s-node2 disktype-
node/k8s-node2 labeled
-------------------------------------------------------------------------------------------------------------------------------
nodeAffinity: 调度分为软性:尝试满足,但不保证(preferred) 硬性:一定满足 (required)
[root@k8s-master cka3]# cat test.yaml
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: disktype
operator: In
values:
- ssd
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: disktype
operator: In
values:
- ssd2
containers:
- name: with-node-affinity
image: nginx
软匹配不一定成功
更多推荐
已为社区贡献29条内容
所有评论(0)