1. nodeName指定
nodeName:指定节点名称,用于将Pod调度到指定的Node上,不经过调度器
apiVersion: v1
kind: Pod
metadata:
name: pod-example
labels:
app: nginx
spec:
nodeName: k8s-node2 # 直接分配
containers:
- name: nginx
image: nginx:1.15
2. 案例
-
编写nodeName直接指定分配
[root@k8s-master pod]# vim kubelet_pod.yaml [root@k8s-master pod]# cat kubelet_pod.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: web name: web spec: replicas: 1 selector: matchLabels: app: web strategy: {} template: metadata: labels: app: web spec: nodeName: k8s-node01 containers: - image: nginx name: nginx
-
启动服务
[root@k8s-master pod]# kubectl apply -f kubelet_pod.yaml deployment.apps/web created
-
验证是否在node01
[root@k8s-master pod]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES web-768c9b7466-s7whv 1/1 Running 0 116s 10.244.85.213 k8s-node01 <none> <none>