This commit is contained in:
huanqing.shao
2019-09-30 07:12:42 +08:00
parent 6914d43c3b
commit f07bac50c2
5 changed files with 87 additions and 3 deletions

View File

@ -292,6 +292,9 @@ module.exports = {
collapsable: true, collapsable: true,
children: [ children: [
'k8s-intermediate/config/taints-toleration/', 'k8s-intermediate/config/taints-toleration/',
'k8s-intermediate/config/taints-toleration/use-case',
'k8s-intermediate/config/taints-toleration/taint-based-evictions',
'k8s-intermediate/config/taints-toleration/taint-nodes-by-condition',
] ]
}, },
{ {

View File

@ -2,9 +2,6 @@
# 在 master 节点和 worker 节点都要执行 # 在 master 节点和 worker 节点都要执行
# 脚本出错时终止执行
set -e
# 安装 docker # 安装 docker
# 参考文档如下 # 参考文档如下
# https://docs.docker.com/install/linux/docker-ce/centos/ # https://docs.docker.com/install/linux/docker-ce/centos/

View File

@ -0,0 +1,46 @@
---
vssueId: 98
titlePrefix: 污点和容忍
layout: LearningLayout
description: Kubernetes教程_在Kubernetes中_配置污点和容忍taints_and_toleration的基于污点的驱逐
---
# 基于污点的驱逐TaintBasedEviction
在前面的章节中,我们描述了 [NoExecute](http://localhost:8080/learning/k8s-intermediate/config/taints-toleration/#%E6%B1%A1%E7%82%B9%E4%B8%8E%E5%AE%B9%E5%BF%8D%E7%9A%84%E5%8C%B9%E9%85%8D) 的污点效果,该效果将对已经运行在节点上的 Pod 施加如下影响:
* 不容忍该污点的 Pod 将立刻被驱逐
* 容忍该污点的 Pod 在未指定 `tolerationSeconds` 的情况下,将继续在该节点上运行
* 容忍该污点的 Pod 在指定了 `tolerationSeconds` 的情况下,将在指定时间超过时从节点上驱逐
此外,自 kubernetes 1.6 以来kubernetes 的节点控制器在碰到某些特定的条件时,将自动为节点添加污点。这类污点有:
* `node.kubernetes.io/not-ready` 节点未就绪。对应着 NodeCondition `Ready``False` 的情况
* `node.kubernetes.io/unreachable` 节点不可触达。对应着 NodeCondition `Ready``Unknown` 的情况
* `node.kubernetes.io/out-of-disk`:节点磁盘空间已满
* `node.kubernetes.io/memory-pressure`:节点内存吃紧
* `node.kubernetes.io/disk-pressure`:节点磁盘吃紧
* `node.kubernetes.io/network-unavailable`:节点网络不可用
* `node.kubernetes.io/unschedulable`:节点不可调度
* `node.cloudprovider.kubernetes.io/uninitialized`:如果 kubelet 是由 "外部" 云服务商启动的该污点用来标识某个节点当前为不可用的状态。在“云控制器”cloud-controller-manager初始化这个节点以后kubelet将此污点移除
自 kubernetes 1.13 开始,上述特性被默认启用。
例如,某一个包含了大量本地状态的应用,在网络断开时,可能仍然想要在节点上停留比较长的时间,以等待网络能够恢复,而避免从节点上驱逐。此时,该 Pod 的容忍可能如下所示:
``` yaml
tolerations:
- key: "node.kubernetes.io/unreachable"
operator: "Exists"
effect: "NoExecute"
tolerationSeconds: 6000
```
如果 Pod 没有 `node.kubernetes.io/not-ready` 容忍,
Kubernetes 将自动为 Pod 添加一个 `tolerationSeconds=300` 的 `node.kubernetes.io/not-ready` 容忍。同样的,如果 Pod 没有 `node.kubernetes.io/unreachable` 容忍Kubernetes 将自动为 Pod 添加一个 `tolerationSeconds=300` 的 `node.kubernetes.io/unreachable` 容忍
这类自动添加的容忍确保了 Pod 在节点发生 `not-ready` 和 `unreachable` 问题时,仍然在节点上保留 5 分钟。
DaemonSet Pod 相对特殊一些,他们在创建时就添加了不带 `tolerationSeconds` 的 `NoExecute` 效果的容忍,适用的污点有:
* `node.kubernetes.io/unreachable`
* `node.kubernetes.io/not-ready`
这将确保 DaemonSet Pod 始终不会被驱逐。

View File

@ -0,0 +1,20 @@
---
vssueId: 99
titlePrefix: 污点和容忍
layout: LearningLayout
description: Kubernetes教程_在Kubernetes中_根据条件为节点添加污点
---
# 条件化的污点TaintNodesByCondition
自 Kubernetes 1.12 开始,`TaintNodesByCondition` 这个特性进入 beta 阶段,此时节点控制器自动根据 Node Condition 为节点创建对应的污点。调度器则不去检查 Node conditions而是检查节点的污点因此 Node Condition 不再直接影响到调度程序。用户通过为 Pod 添加容忍,可以选择性地忽略节点的某些问题(以 Node Condition 呈现的问题)。
`TaintNodesByCondition` 这个特性只会为节点添加 `NoSchedule` 效果的污点。`TaintBasedEviction` Kubernetes 1.13 开始默认生效)则为节点添加 `NoExecute` 效果的污点,参考 [TaintBasedEviction](./taint-based-evictions.html)。
自 Kubernetes 1.8 开始DaemonSet Controller 自动为所有的 DaemonSet Pod 添加如下 `NoSchedule` 效果的容忍,以防止 DaemonSet 不能正常工作:
* `node.kubernetes.io/memory-pressure`
* `node.kubernetes.io/disk-pressure`
* `node.kubernetes.io/out-of-disk`(只对关键 Pod 生效)
* `node.kubernetes.io/unschedulable`(不低于 Kubernetes 1.10
* `node.kubernetes.io/network-unavailable`(只对 host network 生效)

View File

@ -0,0 +1,18 @@
---
vssueId: 97
titlePrefix: 污点和容忍
layout: LearningLayout
description: Kubernetes教程_在Kubernetes中_配置污点和容忍taints_and_toleration的使用案例
---
# 使用案例
污点和容忍使用起来非常灵活,可以用于:
* 避免 Pod 被调度到某些特定的节点
* 从节点上驱逐本不应该在该节点运行的 Pod
具体的场景可能有:
* **专属的节点:** 如果您想将一组节点专门用于特定的场景,您可以为这些节点添加污点(例如 `kubectl taint nodes nodename dedicated=groupName:NoSchedule`)然后向对应的 Pod 添加容忍。带有这些容忍的 Pod 将可以使用这一组专属节点,同时也可以使用集群中的其他节点。如果您想进一步限制这些 Pod 只能使用这一组节点,那么您应该为这一组节点添加一个标签(例如 dedicated=groupName并为这一组 Pod 添加 node affinity或 node selector以限制这些 Pod 只能调度到这一组节点上。
* **带有特殊硬件的节点:** 集群中,如果某一组节点具备特殊的已经(例如 GPU此时非常有必要将那些不需要这类硬件的 Pod 从这组节点上排除掉,以便需要这类硬件的 Pod 可以得到资源。此时您可以为这类节点添加污点(例如:`kubectl taint nodes nodename special=true:NoSchedule` 或者 `kubectl taint nodes nodename special=true:PreferNoSchedule`)并为需要这类硬件的 Pod 添加匹配的容忍。
* **基于污点的驱逐** 当节点出现问题时,可以使用污点以 Pod 为单位从节点上驱逐 Pod。进一步描述请参考 [基于污点的驱逐](./taint-based-evictions.html)