k8s selector_kubernetes调度之NodeSelector及NodeName
本文主要介绍kubernetes调度框架中的NodeName和NodeSelector。1、spec.nodeName用于强制约束将Pod调度到指定的Node节点上,这里说是“调度”,但其实指定了nodeName的Pod会直接跳过Scheduler的调度逻辑,直接写入PodList列表,该匹配规则是强制匹配。如下例:apiVersion: v1kind: ReplicationController
本文主要介绍kubernetes调度框架中的NodeName和NodeSelector。
1、spec.nodeName用于强制约束将Pod调度到指定的Node节点上,这里说是“调度”,但其实指定了nodeName的Pod会直接跳过Scheduler的调度逻辑,直接写入PodList列表,该匹配规则是强制匹配。
如下例:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
labels:
name: nginx
spec:
replicas: 1
selector:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
nodeName: master-168-32
containers:
– name: nginx
image: nginx-ip:0.4
ports:
– containerPort: 80
volumeMounts:
– name: httpd-storage
mountPath: /usr/share/nginx/html
volumes:
– name: httpd-storage
nfs:
server: 10.168.170.218
path: "/data/web"
2、spec.nodeSelector是通过kubernetes的label-selector机制进行节点选择,由scheduler调度策略MatchNodeSelector进行label匹配,调度pod到目标节点,该匹配规则是强制约束。启用节点选择器的步骤为:
[root@master-168-32]# kubectl label nodes node-168-169 china.com/server=high
node "node-168-169" labeled
[root@master-168-32]# kubectl get nodes node-168-169 –show-labels
NAME STATUS ROLES AGE VERSION LABELS
node-168-169 Ready 57d v1.9.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,xxxxxx.com/server=high,kubernetes.io/hostname=node-168-169
如下例:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginxnode
labels:
name: nginxnode
spec:
replicas: 1
selector:
name: nginxnode
template:
metadata:
labels:
name: nginxnode
spec:
nodeSelector:
china.com/server: high
containers:
– name: nginxnode
image: reg.xxxxxx.com/library/nginx-ip:0.4
ports:
– containerPort: 80
volumeMounts:
– name: httpd-storage
mountPath: /usr/share/nginx/html
volumes:
– name: httpd-storage
nfs:
server: 10.168.170.218
path: "/data/web"
更多推荐
所有评论(0)