Kubernetes Pod 调度约束
Kubernetes Pod 调度约束
- 可以将pod调度到指定的节点Node内
- 默认:根据节点资源利用率等分配Node节点。
- nodeName用于将Pod调度到指定的Node名称上
- nodeSelector用于将Pod调度到匹配Label的Node上
工作流程
K8s通过watch实现组件工作。
1、管理员通过命令创建Pod-->apiserver接收到-->状态写入到etcd-->scheduler通过watch获取etcd中获取新的Pod-->通过算法选出pod应该调度到哪些节点内-->绑定到新的节点并更新到etcd中
2、kubelet通过watch从etcd中获取到绑定到自己节点的pod-->将pod通过docker run启动运行--> 在将状态(运行状态)更新到etcd中,根据kubelet周期上报
3、管理员查看pod状态 --> 查找etcd中pod状态 --> 返回给用户
# 使用方法 apiVersion: v1 kind: Pod metadata: name: pod-example labels: app: nginx spec: nodeName: 192.168.31.65 containers: - name: nginx image: nginx:1.15
apiVersion: v1 kind: Pod metadata: name: pod-example spec: nodeSelector: env_role: dev containers: - name: nginx image: nginx:1.15
实践(指定NodeIP)
1、创建测试pod
vim pod5.yaml
apiVersion: v1 kind: Pod metadata: name: pod-example labels: app: nginx spec: nodeName: 192.168.1.111 containers: - name: nginx image: nginx:1.15
2、创建文件
kubectl create -f pod5.yaml
3、查看pod调度节点
NAME READY STATUS RESTARTS AGE IP NODE
pod-example 1/1 Running 0 42s 172.17.1.4 192.168.1.111 <none>
4、查看详情;直接绕过调度器
... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Pulling 9m8s kubelet, 192.168.1.111 pulling image "nginx:1.15" Normal Pulled 8m48s kubelet, 192.168.1.111 Successfully pulled image "nginx:1.15" Normal Created 8m48s kubelet, 192.168.1.111 Created container Normal Started 8m47s kubelet, 192.168.1.111 Started container
实践(指定标签)
1、给指定Node设置标签 ;为 team团队ab队(自定义=自定义)
kubectl label nodes 192.168.1.111 team=a
kubectl label nodes 192.168.1.110 team=b
2、查看标签
NAME STATUS ROLES AGE VERSION LABELS 192.168.1.110 Ready <none> 2d15h v1.12.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.1.110,team=b 192.168.1.111 Ready <none> 2d15h v1.12.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.1.111,team=a
3、创建文件通过标签指定Node
vim pod6.yaml
apiVersion: v1 kind: Pod metadata: name: pod-example spec: nodeSelector: team: b containers: - name: nginx image: nginx:1.15
4、查看状态
NAME READY STATUS RESTARTS AGE IP NODE
pod-example 1/1 Running 0 29s 172.17.84.2 192.168.1.110 <none>
5、查看详情;走默认调度
... node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 83s default-scheduler Successfully assigned default/pod-example to 192.168.1.110 Normal Pulling 81s kubelet, 192.168.1.110 pulling image "nginx:1.15" Normal Pulled 67s kubelet, 192.168.1.110 Successfully pulled image "nginx:1.15" Normal Created 66s kubelet, 192.168.1.110 Created container mal Started 66s kubelet, 192.168.1.110 Started container