定义
使用pod的Nodename 或 NodeSelector 字段调度到指定node节点
nodeName路径
[root@k8smaster4 ns]# kubectl explain pod.spec.nodeName
编写Yaml文件
[root@k8smaster4 ns]# vi pod-second.yaml
apiVersion: v1
kind: Pod
metadata:
name: demo-pod
namespace: default
labels:
app: myapp
env: dev
spec:
nodeName: k8snode4
containers:
- name: tomcat-pod-java
ports:
- containerPort: 8080
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
- name: busybox
image: docker.io/library/busybox:1.28
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
进入Pod某个容器
[root@k8smaster4 ns]# kubectl exec -it demo-pod -c tomcat-pod-java -- /bin/bash
nodeSelector 路径
[root@k8smaster4 ns]# kubectl explain pod.spec.nodeSelector
查看Node标签
[root@k8smaster4 ns]# kubectl get nodes --show-labels
编写nodeSelectorYaml
[root@k8smaster4 ns]# cat node-select.yaml
apiVersion: v1
kind: Pod
metadata:
name: node-seletor
namespace: default
labels:
app: myapp-1
env: env
spec:
nodeSeletor:
disk: ceph
containers:
- name: tomcat-pod-java
ports:
- containerPort: 8080
image: docker.io/xianchao/tomcat-8.5-jre8
imagePullPolicy: IfNotPresent
查看Pod详细信息
[root@k8smaster4 ns]# kubectl describe pod node-selector
添加node标签
[root@k8smaster4 ns]# kubectl label node k8snode4 disk=ceph
查看node标签
[root@k8smaster4 ns]# kubectl get nodes --show-labels
查看某个node标签
[root@k8smaster4 ns]# kubectl get nodes k8snode4 --show-labels
删除node标签
[root@k8smaster4 ns]# kubectl label nodes k8snode4 disk-