1
1
---
2
2
title : 将 Pod 分配给节点
3
3
content_type : concept
4
- weight : 50
4
+ weight : 20
5
5
---
6
6
7
7
<!--
@@ -11,24 +11,24 @@ reviewers:
11
11
- bsalamat
12
12
title: Assigning Pods to Nodes
13
13
content_type: concept
14
- weight: 50
14
+ weight: 20
15
15
-->
16
16
17
17
<!-- overview -->
18
18
19
19
<!--
20
- You can constrain a {{< glossary_tooltip text="Pod" term_id="pod" >}} to only be able to run on particular
21
- {{< glossary_tooltip text="Node(s)" term_id="node" >}}, or to prefer to run on particular nodes .
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
22
There are several ways to do this, and the recommended approaches all use
23
- [label selectors](/docs/concepts/overview/working-with-objects/labels/) to make the selection.
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, not place the pod on a node with insufficient free resources, etc.)
25
+ (e.g. spread your pods across nodes so as not place the pod on a node with insufficient free resources, etc.)
26
26
but there are some circumstances where you may want more control on a node where a pod lands, for example to ensure
27
27
that a pod ends up on a machine 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" >}} 只能在特定的
31
- {{< glossary_tooltip text="节点" term_id="node" >}} 上运行,或者优先运行在特定的节点上 。
31
+ {{< glossary_tooltip text="节点" term_id="node" >}} 上运行。
32
32
有几种方法可以实现这点,推荐的方法都是用
33
33
[ 标签选择算符] ( /zh/docs/concepts/overview/working-with-objects/labels/ ) 来进行选择。
34
34
通常这样的约束不是必须的,因为调度器将自动进行合理的放置(比如,将 Pod 分散到节点上,
@@ -132,22 +132,12 @@ Pod 将会调度到将标签添加到的节点上。
132
132
# # Interlude: built-in node labels {#built-in-node-labels}
133
133
134
134
In addition to labels you [attach](#step-one-attach-label-to-the-node), nodes come pre-populated
135
- with a standard set of labels. These labels are
135
+ with a standard set of labels. See [Well-Known Labels, Annotations and Taints](/docs/reference/ labels-annotations-taints/) for a list of these.
136
136
-->
137
137
# # 插曲:内置的节点标签 {#built-in-node-labels}
138
138
139
139
除了你[添加](#attach-labels-to-node)的标签外,节点还预先填充了一组标准标签。
140
- 这些标签有:
141
-
142
- * [`kubernetes.io/hostname`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#kubernetes-io-hostname)
143
- * [`failure-domain.beta.kubernetes.io/zone`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#failure-domainbetakubernetesiozone)
144
- * [`failure-domain.beta.kubernetes.io/region`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#failure-domainbetakubernetesioregion)
145
- * [`topology.kubernetes.io/zone`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#topologykubernetesiozone)
146
- * [`topology.kubernetes.io/region`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#topologykubernetesiozone)
147
- * [`beta.kubernetes.io/instance-type`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#beta-kubernetes-io-instance-type)
148
- * [`node.kubernetes.io/instance-type`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#nodekubernetesioinstance-type)
149
- * [`kubernetes.io/os`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#kubernetes-io-os)
150
- * [`kubernetes.io/arch`](/zh/docs/reference/kubernetes-api/labels-annotations-taints/#kubernetes-io-arch)
140
+ 参见[常用标签、注解和污点](/zh/docs/reference/labels-annotations-taints/)。
151
141
152
142
{{< note >}}
153
143
<!--
@@ -247,12 +237,12 @@ Pod 可以调度到哪些节点。
247
237
<!--
248
238
There are currently two types of node affinity, called `requiredDuringSchedulingIgnoredDuringExecution` and
249
239
` preferredDuringSchedulingIgnoredDuringExecution` . You can think of them as "hard" and "soft" respectively,
250
- in the sense that the former specifies rules that *must* be met for a pod to be scheduled onto a node (just like
240
+ in the sense that the former specifies rules that *must* be met for a pod to be scheduled onto a node (similar to
251
241
` nodeSelector` but using a more expressive syntax), while the latter specifies *preferences* that the scheduler
252
242
will try to enforce but will not guarantee. The "IgnoredDuringExecution" part of the names means that, similar
253
243
to how `nodeSelector` works, if labels on a node change at runtime such that the affinity rules on a pod are no longer
254
- met, the pod will still continue to run on the node. In the future we plan to offer
255
- ` requiredDuringSchedulingRequiredDuringExecution` which will be just like `requiredDuringSchedulingIgnoredDuringExecution`
244
+ met, the pod continues to run on the node. In the future we plan to offer
245
+ ` requiredDuringSchedulingRequiredDuringExecution` which will be identical to `requiredDuringSchedulingIgnoredDuringExecution`
256
246
except that it will evict pods from nodes that cease to satisfy the pods' node affinity requirements.
257
247
-->
258
248
目前有两种类型的节点亲和性,分别为 `requiredDuringSchedulingIgnoredDuringExecution` 和
@@ -264,8 +254,8 @@ except that it will evict pods from nodes that cease to satisfy the pods' node a
264
254
如果节点的标签在运行时发生变更,从而不再满足 Pod 上的亲和性规则,那么 Pod
265
255
将仍然继续在该节点上运行。
266
256
将来我们计划提供 `requiredDuringSchedulingRequiredDuringExecution`,
267
- 它将类似于 `requiredDuringSchedulingIgnoredDuringExecution`,
268
- 除了它会将 pod 从不再满足 pod 的节点亲和性要求的节点上驱逐。
257
+ 它将与 `requiredDuringSchedulingIgnoredDuringExecution` 完全相同 ,
258
+ 只是它会将 Pod 从不再满足 Pod 的节点亲和性要求的节点上驱逐。
269
259
270
260
<!--
271
261
Thus an example of `requiredDuringSchedulingIgnoredDuringExecution` would be "only run the pod on nodes with Intel CPUs"
@@ -538,22 +528,23 @@ Pod 亲和性与反亲和性的合法操作符有 `In`,`NotIn`,`Exists`,`D
538
528
然而,出于性能和安全原因,topologyKey 受到一些限制:
539
529
540
530
<!--
541
- 1. For affinity and for `requiredDuringSchedulingIgnoredDuringExecution` pod anti-affinity,
542
- empty `topologyKey` is not allowed.
543
- 2. For `requiredDuringSchedulingIgnoredDuringExecution` pod anti-affinity, the admission controller `LimitPodHardAntiAffinityTopology` was introduced to limit `topologyKey` to `kubernetes.io/hostname`. If you want to make it available for custom topologies, you may modify the admission controller, or simply disable it.
544
- 3. For `preferredDuringSchedulingIgnoredDuringExecution` pod anti-affinity, empty `topologyKey` is interpreted as "all topologies" ("all topologies" here is now limited to the combination of `kubernetes.io/hostname`, `topology.kubernetes.io/zone` and `topology.kubernetes.io/region`).
531
+ 1. For pod affinity, empty `topologyKey` is not allowed in both
532
+ ` requiredDuringSchedulingIgnoredDuringExecution`
533
+ and `preferredDuringSchedulingIgnoredDuringExecution`.
534
+ 2. For pod anti-affinity, empty `topologyKey` is also not allowed in both `requiredDuringSchedulingIgnoredDuringExecution`
535
+ and `preferredDuringSchedulingIgnoredDuringExecution`.
536
+ 3. For `requiredDuringSchedulingIgnoredDuringExecution` pod anti-affinity, the admission controller `LimitPodHardAntiAffinityTopology` was introduced to limit `topologyKey` to `kubernetes.io/hostname`. If you want to make it available for custom topologies, you may modify the admission controller, or disable it.
545
537
4. Except for the above cases, the `topologyKey` can be any legal label-key.
546
538
-->
547
- 1. 对于亲和性与 `requiredDuringSchedulingIgnoredDuringExecution` 要求的
548
- Pod 反亲和性,`topologyKey` 不允许为空。
549
- 2. 对于 `requiredDuringSchedulingIgnoredDuringExecution` 要求的 Pod 反亲和性,
550
- 准入控制器 `LimitPodHardAntiAffinityTopology` 被引入来限制 `topologyKey`
551
- 为 `kubernetes.io/hostname`。
552
- 如果你想设置topologyKey为其他值来用于自定义拓扑结构,你必须修改准入控制器或者禁用它。
553
- 3. 对于 `preferredDuringSchedulingIgnoredDuringExecution` 要求的 Pod 反亲和性,
554
- 空的 `topologyKey` 被解释为“所有拓扑结构”(这里的“所有拓扑结构”限制为
555
- ` kubernetes.io/hostname` ,`topology.kubernetes.io/zone` 和
556
- ` topology.kubernetes.io/region` 的组合)。
539
+ 1. 对于 Pod 亲和性而言,在 `requiredDuringSchedulingIgnoredDuringExecution`
540
+ 和 `preferredDuringSchedulingIgnoredDuringExecution` 中,`topologyKey` 不允许为空。
541
+ 2. 对于 Pod 反亲和性而言,`requiredDuringSchedulingIgnoredDuringExecution`
542
+ 和 `preferredDuringSchedulingIgnoredDuringExecution` 中,`topologyKey`
543
+ 都不可以为空。
544
+ 3. 对于 `requiredDuringSchedulingIgnoredDuringExecution` 要求的 Pod 反亲和性,
545
+ 准入控制器 `LimitPodHardAntiAffinityTopology` 被引入以确保 `topologyKey`
546
+ 只能是 `kubernetes.io/hostname`。如果你希望 `topologyKey` 也可用于其他定制
547
+ 拓扑逻辑,你可以更改准入控制器或者禁用之。
557
548
4. 除上述情况外,`topologyKey` 可以是任何合法的标签键。
558
549
559
550
<!--
@@ -573,6 +564,36 @@ must be satisfied for the pod to be scheduled onto a node.
573
564
所有与 `requiredDuringSchedulingIgnoredDuringExecution` 亲和性与反亲和性
574
565
关联的 `matchExpressions` 必须满足,才能将 pod 调度到节点上。
575
566
567
+ <!--
568
+ # ### Namespace selector
569
+ -->
570
+ # ### 名字空间选择算符
571
+
572
+ {{< feature-state for_k8s_version="v1.21" state="alpha" >}}
573
+
574
+ <!--
575
+ Users can also select matching namespaces using `namespaceSelector`, which is a label query over the set of namespaces.
576
+ The affinity term is applied to the union of the namespaces selected by `namespaceSelector` and the ones listed in the `namespaces` field.
577
+ Note that an empty `namespaceSelector` ({}) matches all namespaces, while a null or empty `namespaces` list and
578
+ null `namespaceSelector` means "this pod's namespace".
579
+ -->
580
+ 用户也可以使用 `namespaceSelector` 选择匹配的名字空间,`namespaceSelector`
581
+ 是对名字空间集合进行标签查询的机制。
582
+ 亲和性条件会应用到 `namespaceSelector` 所选择的名字空间和 `namespaces` 字段中
583
+ 所列举的名字空间之上。
584
+ 注意,空的 `namespaceSelector`({})会匹配所有名字空间,而 null 或者空的
585
+ ` namespaces` 列表以及 null 值 `namespaceSelector` 意味着“当前 Pod 的名字空间”。
586
+
587
+ <!--
588
+ This feature is alpha and disabled by default. You can enable it by setting the
589
+ [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
590
+ ` PodAffinityNamespaceSelector` in both kube-apiserver and kube-scheduler.
591
+ -->
592
+ 此功能特性是 Alpha 版本的,默认是被禁用的。你可以通过针对 kube-apiserver 和
593
+ kube-scheduler 设置
594
+ [特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)
595
+ ` PodAffinityNamespaceSelector` 来启用此特性。
596
+
576
597
<!--
577
598
# ### More Practical Use-cases
578
599
0 commit comments