K8S将pod调度到指定nodes上运行
两种方式
方式1:强制固定
vim text.yaml
nodeName: worker01 #添加节点名参数
apiVersion: v1
kind: Pod
metadata:
name: text
namespace: text
spec:
nodeName: worker01 #添加节点名参数
containers:
- name: hello
image: centos:7
imagePullPolicy: IfNotPresent
command: ["bash","-c","--"]
args: ["while true; do sleep 3;done;"]
kubectl create -f text.yaml
kubectl describe pod text -n text
方式2:使用标签选择器(label-selector)
kubectl label nodes worker03 type=node_type
kubectl get node --show-labels #获取所有节点的标签,得到worker03设置的标签
apiVersion: v1
kind: Pod
metadata:
name: text1
namespace: text
spec:
nodeSelector: #标签选择器参数
type: node_type #刚刚添加的类型
containers:
- name: hello1
image: centos:7
imagePullPolicy: IfNotPresent
command: ["bash","-c","--"]
args: ["while true; do sleep 3;done;"]
kubectl describe pod text1 -n text