This commit is contained in:
huanqing.shao
2019-12-06 22:20:20 +08:00
parent 15db9ceb42
commit 6f8c608504
18 changed files with 301 additions and 26 deletions

View File

@ -0,0 +1,19 @@
---
vssueId: 64
layout: LearningLayout
description: Kubernetes教程_Kubernetes中的亲和性与反亲和性_Affinity_and_Anti-Affinity
meta:
- name: keywords
content: Kubernetes教程,K8S教程,Affinity,anti-affinity,亲和性,反亲和性
---
# 亲和性与反亲和性
> 参考文档:[Affinity and anti-affinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity)
<AdSenseTitle/>
`nodeSelector` 提供了一个非常简单的方式,将 Pod 限定到包含特定标签的节点上。亲和性与反亲和性affinity / anti-affinity特性则极大地扩展了限定的表达方式。主要的增强点在于
1. 表达方式更加有效(不仅仅是多个精确匹配表达式的“和”关系)
2. 可以标识该规则为“soft” / “preference” (软性的、偏好的)而不是 hard requirement必须的此时如果调度器发现该规则不能被满足Pod 仍然可以被调度
3. 可以对比节点上(或其他拓扑域 topological domain已运行的其他 Pod 的标签,而不仅仅是节点自己的标签,此时,可以定义类似这样的规则:某量类 Pod 不能在同一个节点(或拓扑域)上共存

View File

@ -77,9 +77,14 @@ nodeSelector 是 PodSpec 中的一个字段。指定了一组名值对。节点
此时您已完成了通过 nodeSelector 为 Pod 指定节点的任务。
## Node isolation/restriction <Badge text="Kuboard 暂不支持" type="warn"/>
## Node isolation/restriction
向节点对象添加标签后,可以将 Pod 指定到特定(一个或一组)的节点,以便确保某些 Pod 只在具备某些隔离性、安全性或符合管理规定的节点上运行。如果将标签用于这个目的,推荐选择那些不会被 kubelet 修改的标签。这样做可以避免节点非法使用其 kubelet credential 来设置节点自己的标签,进一步影响到调度器将工作负载调度到该节点上。
`NodeRestriction` 管理插件可以阻止 kubelet 设置或者修改节点上以 `node-restriction.kubernetes.io/` 开头的标签。如需要使用该标签前缀作为节点隔离的目的,需要:
1. 确保 kubenetes 已经启用了 [Node authorizer](https://kubernetes.io/docs/reference/access-authn-authz/node/) 和 [NodeRestriction admission plugin](https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/#noderestriction)
2. 添加带 `node-restriction.kubernetes.io/` 前缀的标签到节点对象,并将这些标签作为 Pod 中的节点选择器。例如: `example.com.node-restriction.kubernetes.io/fips=true``example.com.node-restriction.kubernetes.io/pci-dss=true`
请参考 Kubernetes 官网文档 [Node isolation/restriction](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-isolation-restriction)
## Affinity and anti-affinity <Badge text="Kuboard 暂不支持" type="warn"/>