30 Kubernetes深入Pod-Pod调度策略之nodeSelector

释放双眼,带上耳机,听听看~!

nodeSelector用于将Pod调度到匹配Label的Node上,所以要先给node打上标签,然后在Pod配置清单中选择指定Node的标签。
先给规划node用途,然后打标签,例如将两台node划分给不同团队使用:

为Node添加标签

k8s-node02给开发团队用,k8s-node03给大数据团队用

1.添加标签

kubectl label nodes k8s-node02 team=development
kubectl label nodes k8s-node03 team=bigdata

2.查看标签

kubectl get nodes -o wide --show-labels

创建资源配置清单

cat nodeSelector-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nodeselector-pod
spec:
  nodeSelector:                   #指定标签选择器
    team: development               #label指定开发团队的label
  containers:
  - image: busybox:latest
    name: nodeselector-containers
    command: [ "/bin/sh", "-c", "tail -f /etc/passwd" ]

创建Pod对象

kubectl apply -f nodeSelector-pod.yaml

查看pod被分配的Node

kubectl get pods -o wide | grep nodeselect
nodeselector-pod                    1/1     Running            0          49s     10.244.2.47   k8s-node02   <none>           <none>

删除标签

kubectl label nodes k8s-node02 team-
kubectl label nodes k8s-node03 team-

删除标签后pod还在正常运行

kubectl get pods -o wide | grep nodeselect
nodeselector-pod                    1/1     Running            0          11m     10.244.2.47   k8s-node02   <none>           <none>

把Pod删除然后再次创建Pod

kubectl delete pods/nodeselector-pod

kubectl apply -f nodeSelector-pod.yaml

会发现该pod一直在等待中,找不到清单中配置标签的Node

kubectl get pods -o wide | grep nodeselect
nodeselector-pod                    0/1     Pending            0          55s     <none>        <none>       <none>           <none>

事件:6个节点都不匹配 node selector

kubectl describe pods/nodeselector-pod | grep -A 10 Events
Events:
  Type     Reason            Age        From               Message
  ----     ------            ----       ----               -------
  Warning  FailedScheduling  <unknown>  default-scheduler  0/6 nodes are available: 6 node(s) didn't match node selector.
  Warning  FailedScheduling  <unknown>  default-scheduler  0/6 nodes are available: 6 node(s) didn't match node selector.
Ops工具

29. Kubernetes深入Pod-Pod调度策略之nodeName

2020-6-16 11:44:22

Ops工具

31. Kubernetes深入Pod-Pod调度策略之污点与容忍

2020-6-16 11:44:50

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索