一、Pod.spec.nodeName将 Pod 直接调度到指定名称 Node 节点上,会跳过 Scheduler 的调度策略,该匹配规则是强制匹配
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: myweb
spec:
 replicas: 7
 template:
  metadata:
   labels:
    app: myweb
  spec:
   nodeName: k8s-node01    ## 指定节点名称
   containers:
   - name: myweb
     image: wangyanglinux/myapp:v1
     ports:
     - containerPort: 80
查看节点名称
[root@k8s-master01 ~]# kubectl get node
NAME           STATUS   ROLES    AGE   VERSION
k8s-master01   Ready    master   23d   v1.15.1
k8s-node01     Ready    <none>   23d   v1.15.1
k8s-node02     Ready    <none>   23d   v1.15.1
二、 Pod.spec.nodeSelector:通过 kubernetes 的 label-selector 机制选择节点,由调度器调度策略匹配 label,而后调度 Pod 到目标节点,该匹配规则属于强制约束
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: myweb1111
spec:
 replicas: 7
 template:
  metadata:
   labels:
    app: myweb11
  spec:
   nodeSelector:
    type: ssd      #指定节点的标签的键和值
   containers:
   - name: myweb11
     image: wangyanglinux/myapp:v1
     ports:
     - containerPort: 80
查看node标签
[root@k8s-master01 ~]# kubectl get node k8s-node01 --show-labels
NAME         STATUS   ROLES    AGE   VERSION   LABELS
k8s-node01   Ready    <none>   23d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01,kubernetes.io/os=linux,type=ssd
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐