k8s通过nodeaffinity调度方式创建pod
官网文档介绍通过下图简要介绍在node节点135上配置的label:key-affinity-label=value-affinity-labelroot@server01:~# kubectl label node 192.168.174.135 key-affinity-label=value-affinity-labelnode "192.168.174.135" labeled...
·
官网文档介绍
通过下图简要介绍
在node节点135上配置的label:key-affinity-label=value-affinity-label
root@server01:~# kubectl label node 192.168.174.135 key-affinity-label=value-affinity-label
node "192.168.174.135" labeled
136服务器k8s master
/root/demo/node-affinity.yaml
在yaml文件中配置label的key;key: key-affinity-label
value-affinity-label
apiVersion: v1
kind: Pod
metadata:
labels:
run: node-affinity
name: node-affinity
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: node-affinity
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: key-affinity-label
operator: In
values:
- "value-affinity-label"
创建
kubectl create -f node-affinity.yaml
查看node-affinity就创建在了135节点
root@server02:~/demo# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
node-affinity 1/1 Running 0 28m 172.20.188.20 192.168.174.135
pod-manual-schedule 1/1 Running 0 3h 172.20.188.19 192.168.174.135
pod-schedule 1/1 Running 0 3h 172.20.40.205 192.168.174.137
刚开始配置的时候,因为key和value与所有3台node的label都不匹配,所以执行命令调度创建的时候,查看创建状态一直都是pending
root@server02:~/demo# kubectl get pod
NAME READY STATUS RESTARTS AGE
node-affinity 0/1 Pending 0 13m
查看日志
kubectl describe pod node-affinity
提示default-scheduler 0/3 nodes are available: 3 MatchNodeSelector
.
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 2m (x72 over 22m) default-scheduler 0/3 nodes are available: 3 MatchNodeSelector.
更多推荐
已为社区贡献19条内容
所有评论(0)