k8s 污点(Taint) 和容忍度(Toleration)使用

  • key:

  • value:

  • effect:

    • NoSchedule

    • PreferNoSchedule

    • NoExecute

  • key:

  • operator:

    • Equal

    • Exists

  • value:operatorEqual

  • effect:

  • gpu=true:NoSchedulegpu=true:NoSchedule

  • NoExecute

kubectl taint nodes <node-name> key1=value1:NoSchedule

<node-name>key1value1NoSchedule

apiVersion: v1
 
kind: Pod
 
metadata:
 
  name: my-pod
 
spec:
 
  containers:
 
  - name: my-container
 
    image: nginx:latest
 
  tolerations:
 
  - key: "key1"
 
    operator: "Equal"
 
    value: "value1"
 
    effect: "NoSchedule"

my-podkey1=value1:NoSchedule

Exists

apiVersion: v1
 
kind: Pod
 
metadata:
 
  name: my-pod
 
spec:
 
  containers:
 
  - name: my-container
 
    image: nginx:latest
 
  tolerations:
 
  - key: "key1"
 
    operator: "Exists"
 
    effect: "NoSchedule"

my-podkey1

  • Existskeyvalueeffect)。

  • kubectl taint nodes <node-name> <key>-

tolerations

  • kubectl taint nodes node1 key1=value1:NoSchedule

  • kubectl taint nodes node1 key1=value1:NoExecute

  • kubectl taint nodes node1 key2=value2:NoSchedule

tolerations:
 
- key: "key1"
 
  operator: "Equal"
 
  value: "value1"
 
  effect: "NoSchedule"
 
- key: "key1"
 
  operator: "Equal"
 
  value: "value1"
 
  effect: "NoExecute"

tolerations:
 
- key: "key1"
 
  operator: "Equal"
 
  value: "value1"
 
  effect: "NoExecute"
 
  tolerationSeconds: 3600

  • key=env,value=prod,effect=NoSchedule

  • key=disktype,value=ssd,effect=NoSchedule

  • key=zone,value=us-east-1,effect=NoSchedule

tolerations

apiVersion: v1
 
kind: Pod
 
metadata:
 
  name: my-pod
 
spec:
 
  containers:
 
  - name: my-container
 
    image: nginx:latest
 
  tolerations:
 
  - key: "env"
 
    operator: "Equal"
 
    value: "prod"
 
    effect: "NoSchedule"
 
  - key: "disktype"
 
    operator: "Equal"
 
    value: "ssd"
 
    effect: "NoSchedule"
 
  - key: "zone"
 
    operator: "Equal"
 
    value: "us-east-1"
 
    effect: "NoSchedule"

my-pod