Kubernetes 调度器

先建立一个pod4

kubectl apply -f pod4.yaml

这个pod有node亲和性,指定到了cluster-3

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod4
  labels:
    app: myapp-pod4
    version: v1
spec:
  containers: 
  -  name: myapp-pod4
     image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-3.novalocal
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-5.novalocal

kubectl get pod -o wide

给node打污点:

# 设置污点 
kubectl taint nodes node1 key1=value1:NoSchedule 
# 节点说明中,查找 Taints 字段 
kubectl describe pod pod-name 
# 去除污点 
kubectl taint nodes node1 key1:NoSchedule-

加污点:

kubectl taint nodes xgcloud-ops-k8s-cluster-3.novalocal check=wtl:NoExecute

删除污点:

kubectl taint node xgcloud-ops-k8s-cluster-3.novalocal check=wtl:NoExecute-  

查看污点:

kubectl describe node/xgcloud-ops-k8s-cluster-3.novalocal

 

 

 因为不是deployment,所以pod被驱逐之后没有在建立,就没了

容忍(tolerations)

如果 operator 的值是 Exists,则 value 属性可省略

如果 operator 的值是 Equal,则表示其 key 与 value 之间的关系是 equal(等于)

如果不指定 operator 属性,则默认值为 Equal

另外,还有两个特殊值: 空的 key 如果再配合 Exists 就能匹配所有的 key 与 value,也就是是能容忍所有节点的所有 Taints 空的 effect 匹配所有的 effect

给pod4设置容忍

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod4
  labels:
    app: myapp-pod4
    version: v1
spec:
  containers: 
  -  name: myapp-pod4
     image: nginx
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-3.novalocal
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - xgcloud-ops-k8s-cluster-5.novalocal
  tolerations:
  - key: "check"
    operator: "Equal"
    value: "wtl"
    effect: "NoExecute"
    tolerationSeconds: 3600

kubectl get pod -o wide

原文地址:https://www.cnblogs.com/litzhiai/p/14971839.html