1. 程式人生 > 其它 >Kubernetes 汙點 Taint 和容忍 Toleration

Kubernetes 汙點 Taint 和容忍 Toleration

詳細:https://www.ziji.work/kubernetes/kubernetes-stain-taint-toleration.html#1

背景:
有時候我們要對一個node節點進行維修,升級,需要重啟開關機,那怎麼才能做到應用不影響呢?
技術:
我們可以使用 命令操作

封鎖節點,先讓節點變的不可排程

kubectl cordon <node name>
驅逐pod,該操作做完之後就可以進行節點升級等操作

kubectl drain <node name>
官方文件:
https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain

子命令

```bash
Options:
--delete-local-data=false: Continue even if there are pods using emptyDir (local data that will be deleted when
the node is drained).
--dry-run=false: If true, only print the object that would be sent, without sending it.
--force=false: Continue even if there are pods not managed by a ReplicationController, ReplicaSet, Job, DaemonSet
or StatefulSet.
--grace-period=-1: Period of time in seconds given to each pod to terminate gracefully. If negative, the default
value specified in the pod will be used.
--ignore-daemonsets=false: Ignore DaemonSet-managed pods.
--pod-selector='': Label selector to filter pods on the node
-l, --selector='': Selector (label query) to filter on
--timeout=0s: The length of time to wait before giving up, zero means infinite

Usage:
kubectl drain NODE [options]



注意:如果執行過程中不需要驅逐 DS容器,使用–ignore-daemonsets=false
執行之後會有error報錯 ,請忽略


解封鎖

kubectl uncordon <node name>
之後正常使用

如果想移除某個節點

kubectl delete node <node name>