污点和容忍

污点和容忍

   运维菜鸟     2022年3月20日 22:16     1612    

1、污点

在节点专门有一个和Labels类似的字段是用来给节点标记不可用的标志,就是taint

可以适用命令

kubectl describe node k8s-node1查看

1.png 

使用下边命令给节点打上污点

Kubectl taint nodes k8s-node1 key=value:NoSchedule

取消

Kubect taint nodes k8s-node1 key:NoSchedule-

可以定义多个污点

Keyvalue是自己定义的

NoSchedulePerferNoScheduleNoExecute分别有不同的含义

NoSchedule :表示k8s将不会将Pod调度到具有该污点的Node

PreferNoSchedule :表示k8s将尽量避免将Pod调度到具有该污点的Node

NoExecute :表示k8s将不会将Pod调度到具有该污点的Node上,同时会将Node上已经存在的Pod驱逐出去

 

2、容忍

tolerations:

- key: "nginx"

  operator: "Equal"

  value: "noschedule"

  effect: "NoSchedule"

或者

tolerations:

- key: "nginx"

  operator: "Exists"

  effect: "NoSchedule"

container同一层级,加上上边字段,pod即可调度到污点节点上。

 

3、示例

假设给node1打上污点

 

apiVersion: apps/v1

kind: Deployment

metadata:

  name: nginx-deployment

  namespace: zjz

  labels:

    app: nginx

spec:

  selector:

    matchLabels:

      app: nginx

  replicas: 1

  strategy:

    type: Recreate

  template:

    metadata:

      labels:

        app: nginx

    spec:

      containers:

      - name: nginx

        image: nginx

        ports:

        - containerPort: 80

      tolerations:

      - key: "nginx"

        operator: "Equal"

        value: "noschedule"

        effect: "NoSchedule"

 

4、命令

可以使用命令

kubectl cordon k8s-node1

可以给节点添加上如下污点

2.png 

然后看node节点的描述

3.png 

如果要取消可以使用

Kubectl uncordon k8s-node1


文章评论

2

其他文章