@@ -18,13 +18,13 @@ weight: 20
18
18
19
19
<!--
20
20
You can constrain a {{< glossary_tooltip text="Pod" term_id="pod" >}} so that it can only run on particular set of
21
- {{< glossary_tooltip text="Node (s)" term_id="node" >}}.
22
- There are several ways to do this, and the recommended approaches all use
21
+ {{< glossary_tooltip text="node (s)" term_id="node" >}}.
22
+ There are several ways to do this and the recommended approaches all use
23
23
[label selectors](/docs/concepts/overview/working-with-objects/labels/) to facilitate the selection.
24
24
Generally such constraints are unnecessary, as the scheduler will automatically do a reasonable placement
25
- (e.g. spread your pods across nodes so as not place the pod on a node with insufficient free resources, etc.)
25
+ (for example, spreading your Pods across nodes so as not place Pods on a node with insufficient free resources).
26
26
However, there are some circumstances where you may want to control which node
27
- the Pod deploys to, for example, to ensure that a Pod ends up on a node with an SSD attached to it, or to co-locate pods from two different
27
+ the Pod deploys to, for example, to ensure that a Pod ends up on a node with an SSD attached to it, or to co-locate Pods from two different
28
28
services that communicate a lot into the same availability zone.
29
29
-->
30
30
你可以约束一个 {{< glossary_tooltip text="Pod" term_id="pod" >}}
@@ -172,6 +172,19 @@ define. Some of the benefits of affinity and anti-affinity include:
172
172
* 你可以使用节点上(或其他拓扑域中)运行的其他 Pod 的标签来实施调度约束,
173
173
而不是只能使用节点本身的标签。这个能力让你能够定义规则允许哪些 Pod 可以被放置在一起。
174
174
175
+ <!--
176
+ The affinity feature consists of two types of affinity:
177
+
178
+ * *Node affinity* functions like the `nodeSelector` field but is more expressive and
179
+ allows you to specify soft rules.
180
+ * *Inter-pod affinity/anti-affinity* allows you to constrain Pods against labels
181
+ on other Pods.
182
+ -->
183
+ 亲和性功能由两种类型的亲和性组成:
184
+
185
+ * ** 节点亲和性** 功能类似于 ` nodeSelector ` 字段,但它的表达能力更强,并且允许你指定软规则。
186
+ * Pod 间亲和性/反亲和性允许你根据其他 Pod 的标签来约束 Pod。
187
+
175
188
<!--
176
189
### Node affinity
177
190
@@ -222,15 +235,16 @@ For example, consider the following Pod spec:
222
235
<!--
223
236
In this example, the following rules apply:
224
237
225
- * The node *must* have a label with the key `kubernetes.io/os ` and
226
- the value `linux `.
238
+ * The node *must* have a label with the key `topology. kubernetes.io/zone ` and
239
+ the value of that label *must* be either `antarctica-east1` or `antarctica-west1 `.
227
240
* The node *preferably* has a label with the key `another-node-label-key` and
228
241
the value `another-node-label-value`.
229
242
-->
230
243
在这一示例中,所应用的规则如下:
231
244
232
- * 节点必须包含键名为 ` kubernetes.io/os ` 的标签,并且其取值为 ` linux ` 。
233
- * 节点 ** 最好** 具有键名为 ` another-node-label-key ` 且取值为
245
+ * 节点** 必须** 包含一个键名为 ` topology.kubernetes.io/zone ` 的标签,
246
+ 并且该标签的取值** 必须** 为 ` antarctica-east1 ` 或 ` antarctica-west1 ` 。
247
+ * 节点** 最好** 具有一个键名为 ` another-node-label-key ` 且取值为
234
248
` another-node-label-value ` 的标签。
235
249
236
250
<!--
@@ -269,7 +283,7 @@ satisfied.
269
283
<!--
270
284
If you specify multiple `matchExpressions` associated with a single `nodeSelectorTerms`,
271
285
then the Pod can be scheduled onto a node only if all the `matchExpressions` are
272
- satisfied.
286
+ satisfied.
273
287
-->
274
288
如果你指定了多个与同一 ` nodeSelectorTerms ` 关联的 ` matchExpressions ` ,
275
289
则只有当所有 ` matchExpressions ` 都满足时 Pod 才可以被调度到节点上。
@@ -341,8 +355,8 @@ must have existing nodes with the `kubernetes.io/os=linux` label.
341
355
342
356
<!--
343
357
When configuring multiple [scheduling profiles](/docs/reference/scheduling/config/#multiple-profiles), you can associate
344
- a profile with a Node affinity, which is useful if a profile only applies to a specific set of nodes.
345
- To do so, add an `addedAffinity` to the `args` field of the [`NodeAffinity` plugin](/docs/reference/scheduling/config/#scheduling-plugins)
358
+ a profile with a node affinity, which is useful if a profile only applies to a specific set of nodes.
359
+ To do so, add an `addedAffinity` to the `args` field of the [`NodeAffinity` plugin](/docs/reference/scheduling/config/#scheduling-plugins)
346
360
in the [scheduler configuration](/docs/reference/scheduling/config/). For example:
347
361
-->
348
362
在配置多个[ 调度方案] ( /zh-cn/docs/reference/scheduling/config/#multiple-profiles ) 时,
@@ -410,7 +424,7 @@ Inter-pod affinity and anti-affinity allow you to constrain which nodes your
410
424
Pods can be scheduled on based on the labels of **Pods** already running on that
411
425
node, instead of the node labels.
412
426
-->
413
- # ## pod 间亲和性与反亲和性 {#inter-pod-affinity-and-anti-affinity}
427
+ # ## Pod 间亲和性与反亲和性 {#inter-pod-affinity-and-anti-affinity}
414
428
415
429
Pod 间亲和性与反亲和性使你可以基于已经在节点上运行的 **Pod** 的标签来约束
416
430
Pod 可以调度到的节点,而不是基于节点上的标签。
@@ -552,9 +566,9 @@ same zone currently running Pods with the `Security=S2` Pod label.
552
566
553
567
<!--
554
568
To get yourself more familiar with the examples of Pod affinity and anti-affinity,
555
- refer to the [design proposal](https://github.com/kubernetes/ design-proposals-archive/blob/main /scheduling/podaffinity.md).
569
+ refer to the [design proposal](https://git.k8s.io/ design-proposals-archive/scheduling/podaffinity.md).
556
570
-->
557
- 查阅[设计文档](https://github.com/kubernetes/ design-proposals-archive/blob/main /scheduling/podaffinity.md)
571
+ 查阅[设计文档](https://git.k8s.io/ design-proposals-archive/scheduling/podaffinity.md)
558
572
以进一步熟悉 Pod 亲和性与反亲和性的示例。
559
573
560
574
<!--
@@ -571,8 +585,7 @@ exceptions for performance and security reasons:
571
585
有一些限制:
572
586
573
587
<!--
574
- * For Pod affinity and anti-affinity, an empty `topologyKey` field is not allowed in both
575
- ` requiredDuringSchedulingIgnoredDuringExecution`
588
+ * For Pod affinity and anti-affinity, an empty `topologyKey` field is not allowed in both `requiredDuringSchedulingIgnoredDuringExecution`
576
589
and `preferredDuringSchedulingIgnoredDuringExecution`.
577
590
* For `requiredDuringSchedulingIgnoredDuringExecution` Pod anti-affinity rules,
578
591
the admission controller `LimitPodHardAntiAffinityTopology` limits
@@ -634,6 +647,14 @@ Pod 间亲和性与反亲和性在与更高级别的集合(例如 ReplicaSet
634
647
Deployment 等)一起使用时,它们可能更加有用。
635
648
这些规则使得你可以配置一组工作负载,使其位于相同定义拓扑(例如,节点)中。
636
649
650
+ <!--
651
+ Take, for example, a three-node cluster running a web application with an
652
+ in-memory cache like redis. You could use inter-pod affinity and anti-affinity
653
+ to co-locate the web servers with the cache as much as possible.
654
+ -->
655
+ 以一个三节点的集群为例,该集群运行一个带有 Redis 这种内存缓存的 Web 应用程序。
656
+ 你可以使用节点间的亲和性和反亲和性来尽可能地将 Web 服务器与缓存并置。
657
+
637
658
<!--
638
659
In the following example Deployment for the redis cache, the replicas get the label `app=store`. The
639
660
` podAntiAffinity` rule tells the scheduler to avoid placing multiple replicas
@@ -803,16 +824,16 @@ The above Pod will only run on the node `kube-01`.
803
824
804
825
<!--
805
826
* Read more about [taints and tolerations](/docs/concepts/scheduling-eviction/taint-and-toleration/) .
806
- * Read the design docs for [node affinity](https://git.k8s.io/community/contributors/ design-proposals/scheduling/nodeaffinity.md)
807
- and for [inter-pod affinity/anti-affinity](https://git.k8s.io/community/contributors/ design-proposals/scheduling/podaffinity.md).
827
+ * Read the design docs for [node affinity](https://git.k8s.io/design-proposals-archive /scheduling/nodeaffinity.md)
828
+ and for [inter-pod affinity/anti-affinity](https://git.k8s.io/design-proposals-archive /scheduling/podaffinity.md).
808
829
* Learn about how the [topology manager](/docs/tasks/administer-cluster/topology-manager/) takes part in node-level
809
830
resource allocation decisions.
810
831
* Learn how to use [nodeSelector](/docs/tasks/configure-pod-container/assign-pods-nodes/).
811
832
* Learn how to use [affinity and anti-affinity](/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/).
812
833
-->
813
834
* 进一步阅读[污点与容忍度](/zh-cn/docs/concepts/scheduling-eviction/taint-and-toleration/)文档。
814
- * 阅读[节点亲和性](https://git.k8s.io/community/contributors/ design-proposals/scheduling/nodeaffinity.md)
815
- 和[Pod 间亲和性与反亲和性](https://git.k8s.io/community/contributors/ design-proposals/scheduling/podaffinity.md)
835
+ * 阅读[节点亲和性](https://git.k8s.io/design-proposals-archive /scheduling/nodeaffinity.md)
836
+ 和[Pod 间亲和性与反亲和性](https://git.k8s.io/design-proposals-archive /scheduling/podaffinity.md)
816
837
的设计文档。
817
838
* 了解[拓扑管理器](/zh-cn/docs/tasks/administer-cluster/topology-manager/)如何参与节点层面资源分配决定。
818
839
* 了解如何使用 [nodeSelector](/zh-cn/docs/tasks/configure-pod-container/assign-pods-nodes/)。
0 commit comments