Skip to content

Commit 096f4ed

Browse files
committed
[zh-cn]sync assign-pod-node.md
Signed-off-by: xin.li <[email protected]>
1 parent a388cb0 commit 096f4ed

File tree

1 file changed

+71
-29
lines changed

1 file changed

+71
-29
lines changed

content/zh-cn/docs/concepts/scheduling-eviction/assign-pod-node.md

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ information.
153153
## Affinity and anti-affinity
154154
155155
`nodeSelector` is the simplest way to constrain Pods to nodes with specific
156-
labels. Affinity and anti-affinity expands the types of constraints you can
156+
labels. Affinity and anti-affinity expand the types of constraints you can
157157
define. Some of the benefits of affinity and anti-affinity include:
158158
-->
159159
## 亲和性与反亲和性 {#affinity-and-anti-affinity}
@@ -233,6 +233,7 @@ your Pod spec.
233233
For example, consider the following Pod spec:
234234
-->
235235
你可以使用 Pod 规约中的 `.spec.affinity.nodeAffinity` 字段来设置节点亲和性。
236+
236237
例如,考虑下面的 Pod 规约:
237238

238239
{{% code_sample file="pods/pod-with-node-affinity.yaml" %}}
@@ -432,22 +433,26 @@ DaemonSet 控制器创建 Pod 时,默认的 Kubernetes 调度器负责放置 P
432433
### Inter-pod affinity and anti-affinity
433434

434435
Inter-pod affinity and anti-affinity allow you to constrain which nodes your
435-
Pods can be scheduled on based on the labels of **Pods** already running on that
436+
Pods can be scheduled on based on the labels of Pods already running on that
436437
node, instead of the node labels.
437438
-->
438439
### Pod 间亲和性与反亲和性 {#inter-pod-affinity-and-anti-affinity}
439440

440-
Pod 间亲和性与反亲和性使你可以基于已经在节点上运行的 **Pod** 的标签来约束
441+
Pod 间亲和性与反亲和性使你可以基于已经在节点上运行的 Pod 的标签来约束
441442
Pod 可以调度到的节点,而不是基于节点上的标签。
442443

443444
<!--
444-
Inter-pod affinity and anti-affinity rules take the form "this
445+
#### Types of Inter-pod Affinity and Anti-affinity
446+
447+
Inter-pod affinity and anti-affinity take the form "this
445448
Pod should (or, in the case of anti-affinity, should not) run in an X if that X
446449
is already running one or more Pods that meet rule Y", where X is a topology
447450
domain like node, rack, cloud provider zone or region, or similar and Y is the
448451
rule Kubernetes tries to satisfy.
449452
-->
450-
Pod 间亲和性与反亲和性的规则格式为“如果 X 上已经运行了一个或多个满足规则 Y 的 Pod,
453+
#### Pod 间亲和性与反亲和性的类型
454+
455+
Pod 间亲和性与反亲和性的格式为“如果 X 上已经运行了一个或多个满足规则 Y 的 Pod,
451456
则这个 Pod 应该(或者在反亲和性的情况下不应该)运行在 X 上”。
452457
这里的 X 可以是节点、机架、云提供商可用区或地理区域或类似的拓扑域,
453458
Y 则是 Kubernetes 尝试满足的规则。
@@ -496,13 +501,9 @@ Pod 反亲和性需要节点上存在一致性的标签。换言之,
496501
{{< /note >}}
497502

498503
<!--
499-
#### Types of inter-pod affinity and anti-affinity
500-
501504
Similar to [node affinity](#node-affinity) are two types of Pod affinity and
502505
anti-affinity as follows:
503506
-->
504-
#### Pod 间亲和性与反亲和性的类型
505-
506507
与[节点亲和性](#node-affinity)类似,Pod 的亲和性与反亲和性也有两种类型:
507508

508509
- `requiredDuringSchedulingIgnoredDuringExecution`
@@ -530,13 +531,54 @@ spec.
530531
对于 Pod 间反亲和性,可以使用 Pod 规约中的 `.affinity.podAntiAffinity` 字段。
531532

532533
<!--
533-
#### Scheduling a group of pods with inter-pod affinity to themselves
534+
#### Scheduling Behavior
535+
536+
When scheduling a new Pod, the Kubernetes scheduler evaluates the Pod's affinity/anti-affinity rules in the context of the current cluster state:
537+
538+
1. Hard Constraints (Node Filtering):
539+
- `podAffinity.requiredDuringSchedulingIgnoredDuringExecution` and `podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution`:
540+
- The scheduler ensures the new Pod is assigned to nodes that satisfy these required affinity and anti-affinity rules based on existing Pods.
541+
-->
542+
#### 调度行为
543+
544+
在调度新 Pod 时,Kubernetes 调度器会根据当前集群状态评估 Pod 的亲和性/反亲和性规则:
545+
546+
1. 硬约束(节点过滤):
547+
- `podAffinity.requiredDuringSchedulingIgnoredDuringExecution`
548+
`podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution`
549+
- 调度器基于现有 Pod,确保新 Pod 被分配到满足这些必需的亲和性和反亲和性规则的节点上。
550+
551+
<!--
552+
2. Soft Constraints (Scoring):
553+
- `podAffinity.preferredDuringSchedulingIgnoredDuringExecution` and `podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution`:
554+
- The scheduler scores nodes based on how well they meet these preferred affinity and anti-affinity rules to optimize Pod placement.
555+
-->
556+
2. 软约束(评分):
557+
- `podAffinity.preferredDuringSchedulingIgnoredDuringExecution`
558+
`podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution`
559+
- 调度器根据节点满足这些优选的亲和性和反亲和性规则的程度来评分,以优化 Pod 的放置。
560+
561+
<!--
562+
3. Ignored Fields:
563+
- Existing Pods' `podAffinity.preferredDuringSchedulingIgnoredDuringExecution`:
564+
- These preferred affinity rules are not considered during the scheduling decision for new Pods.
565+
- Existing Pods' `podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution`:
566+
- Similarly, preferred anti-affinity rules of existing Pods are ignored during scheduling.
567+
-->
568+
3. 忽略的字段:
569+
- 现有 Pod 的 `podAffinity.preferredDuringSchedulingIgnoredDuringExecution`:
570+
- 在为新 Pod 做调度决策时,不会考虑这些优选的亲和性规则。
571+
- 现有 Pod 的 `podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution`:
572+
- 同样,在调度时会忽略现有 Pod 的优选反亲和性规则。
573+
574+
<!--
575+
#### Scheduling a Group of Pods with Inter-pod Affinity to Themselves
534576

535577
If the current Pod being scheduled is the first in a series that have affinity to themselves,
536578
it is allowed to be scheduled if it passes all other affinity checks. This is determined by
537-
verifying that no other pod in the cluster matches the namespace and selector of this pod,
538-
that the pod matches its own terms, and the chosen node matches all requested topologies.
539-
This ensures that there will not be a deadlock even if all the pods have inter-pod affinity
579+
verifying that no other Pod in the cluster matches the namespace and selector of this Pod,
580+
that the Pod matches its own terms, and the chosen node matches all requested topologies.
581+
This ensures that there will not be a deadlock even if all the Pods have inter-pod affinity
540582
specified.
541583
-->
542584
#### 调度一组具有 Pod 间亲和性的 Pod {#scheduling-a-group-of-pods-with-inter-pod-affinity-to-themselves}
@@ -548,7 +590,7 @@ specified.
548590
这确保即使所有的 Pod 都配置了 Pod 间亲和性,也不会出现调度死锁的情况。
549591

550592
<!--
551-
#### Pod affinity example {#an-example-of-a-pod-that-uses-pod-affinity}
593+
#### Pod Affinity example {#an-example-of-a-pod-that-uses-pod-affinity}
552594

553595
Consider the following Pod spec:
554596
-->
@@ -613,8 +655,7 @@ refer to the [design proposal](https://git.k8s.io/design-proposals-archive/sched
613655
You can use the `In`, `NotIn`, `Exists` and `DoesNotExist` values in the
614656
`operator` field for Pod affinity and anti-affinity.
615657
-->
616-
你可以针对 Pod 间亲和性与反亲和性为其 `operator` 字段使用 `In`、`NotIn`、`Exists`、
617-
`DoesNotExist` 等值。
658+
你可以针对 Pod 间亲和性与反亲和性为其 `operator` 字段使用 `In`、`NotIn`、`Exists`、`DoesNotExist` 等值。
618659

619660
<!--
620661
Read [Operators](#operators)
@@ -658,7 +699,7 @@ affinity/anti-affinity definition appears.
658699
如果 `namespaces` 被忽略或者为空,则默认为 Pod 亲和性/反亲和性的定义所在的名字空间。
659700

660701
<!--
661-
#### Namespace selector
702+
#### Namespace Selector
662703
-->
663704
#### 名字空间选择算符 {#namespace-selector}
664705

@@ -695,17 +736,18 @@ When you want to disable it, you have to disable it explicitly via the
695736

696737
<!--
697738
Kubernetes includes an optional `matchLabelKeys` field for Pod affinity
698-
or anti-affinity. The field specifies keys for the labels that should match with the incoming Pod's labels,
739+
or anti-affinity. The field specifies keys for the labels that should match with the incoming Pod's labels,
699740
when satisfying the Pod (anti)affinity.
700741

701-
The keys are used to look up values from the pod labels; those key-value labels are combined
742+
The keys are used to look up values from the Pod labels; those key-value labels are combined
702743
(using `AND`) with the match restrictions defined using the `labelSelector` field. The combined
703-
filtering selects the set of existing pods that will be taken into Pod (anti)affinity calculation.
744+
filtering selects the set of existing Pods that will be taken into Pod (anti)affinity calculation.
704745
-->
705746
Kubernetes 在 Pod 亲和性或反亲和性中包含一个可选的 `matchLabelKeys` 字段。
706747
此字段指定了应与传入 Pod 的标签匹配的标签键,以满足 Pod 的(反)亲和性。
707748

708-
这些键用于从 Pod 的标签中查找值;这些键值标签与使用 `labelSelector` 字段定义的匹配限制组合(使用 `AND` 操作)。
749+
这些键用于从 Pod 的标签中查找值;这些键值标签与使用 `labelSelector`
750+
字段定义的匹配限制组合(使用 `AND` 操作)。
709751
这种组合的过滤机制选择将用于 Pod(反)亲和性计算的现有 Pod 集合。
710752

711753
{{< caution >}}
@@ -803,11 +845,11 @@ When you want to disable it, you have to disable it explicitly via the
803845

804846
<!--
805847
Kubernetes includes an optional `mismatchLabelKeys` field for Pod affinity
806-
or anti-affinity. The field specifies keys for the labels that should **not** match with the incoming Pod's labels,
848+
or anti-affinity. The field specifies keys for the labels that should not match with the incoming Pod's labels,
807849
when satisfying the Pod (anti)affinity.
808850
-->
809851
Kubernetes 为 Pod 亲和性或反亲和性提供了一个可选的 `mismatchLabelKeys` 字段。
810-
此字段指定了在满足 Pod(反)亲和性时,**不**应与传入 Pod 的标签匹配的键。
852+
此字段指定了在满足 Pod(反)亲和性时,不应与传入 Pod 的标签匹配的键。
811853

812854
{{< caution >}}
813855
<!--
@@ -841,20 +883,20 @@ spec:
841883
affinity:
842884
podAffinity:
843885
requiredDuringSchedulingIgnoredDuringExecution:
844-
# ensure that pods associated with this tenant land on the correct node pool
886+
# ensure that Pods associated with this tenant land on the correct node pool
845887
- matchLabelKeys:
846888
- tenant
847889
topologyKey: node-pool
848890
podAntiAffinity:
849891
requiredDuringSchedulingIgnoredDuringExecution:
850-
# ensure that pods associated with this tenant can't schedule to nodes used for another tenant
892+
# ensure that Pods associated with this tenant can't schedule to nodes used for another tenant
851893
- mismatchLabelKeys:
852894
- tenant # whatever the value of the "tenant" label for this Pod, prevent
853895
# scheduling to nodes in any pool where any Pod from a different
854896
# tenant is running.
855897
labelSelector:
856898
# We have to have the labelSelector which selects only Pods with the tenant label,
857-
# otherwise this Pod would have Pods from daemonsets as well, for example,
899+
# otherwise this Pod would have anti-affinity against Pods from daemonsets as well, for example,
858900
# which aren't supposed to have the tenant label.
859901
matchExpressions:
860902
- key: tenant
@@ -887,8 +929,8 @@ spec:
887929
# 都会阻碍此 Pod 被调度到这些节点池中的节点上
888930
labelSelector:
889931
# 我们必须有一个 labelSelector,只选择具有 “tenant” 标签的 Pod,
890-
# 否则此 Pod 也会与来自 DaemonSet 的 Pod 发生冲突
891-
# 而这些 Pod 不应该具有 “tenant” 标签
932+
# 否则此 Pod 也会与来自 DaemonSet 的 Pod 产生反亲和性
933+
# 例如,这些 Pod 不应该具有 “tenant” 标签
892934
matchExpressions:
893935
- key: tenant
894936
operator: Exists
@@ -1173,7 +1215,7 @@ The following operators can only be used with `nodeAffinity`.
11731215
{{<note>}}
11741216
<!--
11751217
`Gt` and `Lt` operators will not work with non-integer values. If the given value
1176-
doesn't parse as an integer, the pod will fail to get scheduled. Also, `Gt` and `Lt`
1218+
doesn't parse as an integer, the Pod will fail to get scheduled. Also, `Gt` and `Lt`
11771219
are not available for `podAffinity`.
11781220
-->
11791221
`Gt` 和 `Lt` 操作符不能与非整数值一起使用。

0 commit comments

Comments
 (0)