1 NodeName
Pod.spec.nodeName用于强制约束将Pod调度到指定的Node节点上,这里说是“调度”,但其实指定了nodeName的Pod会直接跳过Scheduler的调度逻辑,直接写入PodList列表,该匹配规则是强制匹配
。
例子:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-test
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
nodeName: 192.168.56.13 # 指定pod调度到该节点
containers:
- name: nginx
image: nginx:latest
imagePullPolicy: IfNotPresent # 镜像拉取策略
ports:
- containerPort: 80
2 NodeSelector
Pod.spec.nodeSelector是通过kubernetes的label-selector机制进行节点选择,由scheduler调度策略MatchNodeSelector进行label匹配,调度pod到目标节点,该匹配规则是强制约束
。启用节点选择器的步骤为:
Node添加label标记
标记规则:
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes 192.168.56.13 server_type=game_server
确认标记
[root@linux-node1 ~]# kubectl get nodes 192.168.56.14 --show-labels
NAME STATUS ROLES AGE VERSION LABELS
192.168.56.14 Ready <none> 81d v1.10.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=192.168.56.14,server_type=game_server
Pod定义中添加nodeSelector
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-test
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
nodeSelector:
server_type: game_server #指定调度节点为带有label标记为server_type=game_server