LAB-09:Pod指定节点部署
LAB 概述
创建一个 Pod,名字为 nginx-kusc00401,镜像地址是 nginx,调度到具有 disk=spinning 标签的节点上。
LAB 预配
# 给 k8s-node-2 节点打标签
user1@k8s-master:~$ kubectl label nodes k8s-node-2 disk=spinning
node/k8s-node-2 labeled
# 查看标签
user1@k8s-master:~$ kubectl get nodes --show-labels | grep spinning
k8s-node-2 Ready <none> 37d v1.22.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=spinning,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node-2,kubernetes.io/os=linux
LAB 答案
# 切换 content
$ kubectl config use-context k8s
# 编写yml文件
$ vim pod-nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-kusc00401
spec:
containers:
- name: nginx
image: nginx:1.18.0
imagePullPolicy: IfNotPresent
nodeSelector:
disk: spinning
# 执行yml文件
$ kubectl apply -f pod-nginx.yaml
user1@k8s-master:~/cka-2022-05-01/9$ kubectl apply -f pod-nginx.yaml
pod/nginx-kusc00401 created
LAB 验证
# 验证 pod 部署在 k8s-node-2 节点
user1@k8s-master:~$ kubectl get pod nginx-kusc00401 -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-kusc00401 1/1 Running 0 69s 10.244.140.93 k8s-node-2 <none> <none>
参考资料
- https://kubernetes.io/zh/docs/tasks/configure-pod-container/assign-pods-nodes/