@@ -8,7 +8,6 @@ weight: 20
8
8
reviewers:
9
9
- davidopp
10
10
- kevin-wangzefeng
11
- - bsalamat
12
11
- alculquicondor
13
12
title: Assigning Pods to Nodes
14
13
content_type: concept
@@ -18,13 +17,13 @@ weight: 20
18
17
<!-- overview -->
19
18
20
19
<!--
21
- You can constrain a {{< glossary_tooltip text="Pod" term_id="pod" >}} so that it is
20
+ You can constrain a {{< glossary_tooltip text="Pod" term_id="pod" >}} so that it is
22
21
_restricted_ to run on particular {{< glossary_tooltip text="node(s)" term_id="node" >}},
23
22
or to _prefer_ to run on particular nodes.
24
23
There are several ways to do this and the recommended approaches all use
25
24
[label selectors](/docs/concepts/overview/working-with-objects/labels/) to facilitate the selection.
26
25
Often, you do not need to set any such constraints; the
27
- {{< glossary_tooltip text="scheduler" term_id="kube-scheduler" >}} will automatically do a reasonable placement
26
+ {{< glossary_tooltip text="scheduler" term_id="kube-scheduler" >}} will automatically do a reasonable placement
28
27
(for example, spreading your Pods across nodes so as not place Pods on a node with insufficient free resources).
29
28
However, there are some circumstances where you may want to control which node
30
29
the Pod deploys to, for example, to ensure that a Pod ends up on a node with an SSD attached to it,
@@ -46,10 +45,10 @@ Pod 被部署到哪个节点。例如,确保 Pod 最终落在连接了 SSD 的
46
45
You can use any of the following methods to choose where Kubernetes schedules
47
46
specific Pods:
48
47
49
- * [nodeSelector](#nodeselector) field matching against [node labels](#built-in-node-labels)
50
- * [Affinity and anti-affinity](#affinity-and-anti-affinity)
51
- * [nodeName](#nodename) field
52
- * [Pod topology spread constraints](#pod-topology-spread-constraints)
48
+ * [nodeSelector](#nodeselector) field matching against [node labels](#built-in-node-labels)
49
+ * [Affinity and anti-affinity](#affinity-and-anti-affinity)
50
+ * [nodeName](#nodename) field
51
+ * [Pod topology spread constraints](#pod-topology-spread-constraints)
53
52
-->
54
53
你可以使用下列方法中的任何一种来选择 Kubernetes 对特定 Pod 的调度:
55
54
@@ -90,7 +89,7 @@ and a different value in other environments.
90
89
Adding labels to nodes allows you to target Pods for scheduling on specific
91
90
nodes or groups of nodes. You can use this functionality to ensure that specific
92
91
Pods only run on nodes with certain isolation, security, or regulatory
93
- properties.
92
+ properties.
94
93
-->
95
94
## 节点隔离/限制 {#node-isolation-restriction}
96
95
@@ -110,7 +109,7 @@ itself so that the scheduler schedules workloads onto the compromised node.
110
109
<!--
111
110
The [`NodeRestriction` admission plugin](/docs/reference/access-authn-authz/admission-controllers/#noderestriction)
112
111
prevents the kubelet from setting or modifying labels with a
113
- `node-restriction.kubernetes.io/` prefix.
112
+ `node-restriction.kubernetes.io/` prefix.
114
113
115
114
To make use of that label prefix for node isolation:
116
115
-->
@@ -138,7 +137,7 @@ kubelet 使用 `node-restriction.kubernetes.io/` 前缀设置或修改标签。
138
137
You can add the `nodeSelector` field to your Pod specification and specify the
139
138
[node labels](#built-in-node-labels) you want the target node to have.
140
139
Kubernetes only schedules the Pod onto nodes that have each of the labels you
141
- specify.
140
+ specify.
142
141
-->
143
142
` nodeSelector ` 是节点选择约束的最简单推荐形式。你可以将 ` nodeSelector ` 字段添加到
144
143
Pod 的规约中设置你希望目标节点所具有的[ 节点标签] ( #built-in-node-labels ) 。
@@ -182,7 +181,7 @@ define. Some of the benefits of affinity and anti-affinity include:
182
181
The affinity feature consists of two types of affinity:
183
182
184
183
* *Node affinity* functions like the `nodeSelector` field but is more expressive and
185
- allows you to specify soft rules.
184
+ allows you to specify soft rules.
186
185
* *Inter-pod affinity/anti-affinity* allows you to constrain Pods against labels
187
186
on other Pods.
188
187
-->
@@ -263,7 +262,7 @@ interpreting the rules. You can use `In`, `NotIn`, `Exists`, `DoesNotExist`,
263
262
264
263
<!--
265
264
`NotIn` and `DoesNotExist` allow you to define node anti-affinity behavior.
266
- Alternatively, you can use [node taints](/docs/concepts/scheduling-eviction/taint-and-toleration/)
265
+ Alternatively, you can use [node taints](/docs/concepts/scheduling-eviction/taint-and-toleration/)
267
266
to repel Pods from specific nodes.
268
267
-->
269
268
` NotIn ` 和 ` DoesNotExist ` 可用来实现节点反亲和性行为。
@@ -323,7 +322,7 @@ The final sum is added to the score of other priority functions for the node.
323
322
Nodes with the highest total score are prioritized when the scheduler makes a
324
323
scheduling decision for the Pod.
325
324
326
- For example, consider the following Pod spec:
325
+ For example, consider the following Pod spec:
327
326
-->
328
327
最终的加和值会添加到该节点的其他优先级函数的评分之上。
329
328
在调度器为 Pod 作出调度决定时,总分最高的节点的优先级也最高。
@@ -550,7 +549,7 @@ The affinity rule says that the scheduler can only schedule a Pod onto a node if
550
549
the node is in the same zone as one or more existing Pods with the label
551
550
` security=S1` . More precisely, the scheduler must place the Pod on a node that has the
552
551
` topology.kubernetes.io/zone=V` label, as long as there is at least one node in
553
- that zone that currently has one or more Pods with the Pod label `security=S1`.
552
+ that zone that currently has one or more Pods with the Pod label `security=S1`.
554
553
-->
555
554
亲和性规则表示,仅当节点和至少一个已运行且有 `security=S1` 的标签的
556
555
Pod 处于同一区域时,才可以将该 Pod 调度到节点上。
@@ -615,7 +614,7 @@ affinity/anti-affinity definition appears.
615
614
-->
616
615
除了 `labelSelector` 和 `topologyKey`,你也可以指定 `labelSelector`
617
616
要匹配的命名空间列表,方法是在 `labelSelector` 和 `topologyKey`
618
- 所在层同一层次上设置 `namespaces`。
617
+ 所在层同一层次上设置 `namespaces`。
619
618
如果 `namespaces` 被忽略或者为空,则默认为 Pod 亲和性/反亲和性的定义所在的命名空间。
620
619
621
620
<!--
@@ -628,7 +627,7 @@ affinity/anti-affinity definition appears.
628
627
<!--
629
628
You can also select matching namespaces using `namespaceSelector`, which is a label query over the set of namespaces.
630
629
The affinity term is applied to namespaces selected by both `namespaceSelector` and the `namespaces` field.
631
- Note that an empty `namespaceSelector` ({}) matches all namespaces, while a null or empty `namespaces` list and
630
+ Note that an empty `namespaceSelector` ({}) matches all namespaces, while a null or empty `namespaces` list and
632
631
null `namespaceSelector` matches the namespace of the Pod where the rule is defined.
633
632
-->
634
633
用户也可以使用 `namespaceSelector` 选择匹配的名字空间,`namespaceSelector`
@@ -641,7 +640,7 @@ null `namespaceSelector` matches the namespace of the Pod where the rule is defi
641
640
# ### More practical use-cases
642
641
643
642
Inter-pod affinity and anti-affinity can be even more useful when they are used with higher
644
- level collections such as ReplicaSets, StatefulSets, Deployments, etc. These
643
+ level collections such as ReplicaSets, StatefulSets, Deployments, etc. These
645
644
rules allow you to configure that a set of workloads should
646
645
be co-located in the same defined topology; for example, preferring to place two related
647
646
Pods onto the same node.
@@ -664,7 +663,7 @@ affinity and anti-affinity to co-locate the web servers with the cache as much a
664
663
你可以使用 Pod 间的亲和性和反亲和性来尽可能地将该 Web 服务器与缓存并置。
665
664
666
665
<!--
667
- In the following example Deployment for the redis cache, the replicas get the label `app=store`. The
666
+ In the following example Deployment for the Redis cache, the replicas get the label `app=store`. The
668
667
` podAntiAffinity` rule tells the scheduler to avoid placing multiple replicas
669
668
with the `app=store` label on a single node. This creates each cache in a
670
669
separate node.
@@ -764,9 +763,9 @@ where each web server is co-located with a cache, on three separate nodes.
764
763
| *webserver-1* | *webserver-2* | *webserver-3* |
765
764
| *cache-1* | *cache-2* | *cache-3* |
766
765
767
- <!--
766
+ <!--
768
767
The overall effect is that each cache instance is likely to be accessed by a single client, that
769
- is running on the same node. This approach aims to minimize both skew (imbalanced load) and latency.
768
+ is running on the same node. This approach aims to minimize both skew (imbalanced load) and latency.
770
769
-->
771
770
总体效果是每个缓存实例都非常可能被在同一个节点上运行的某个客户端访问。
772
771
这种方法旨在最大限度地减少偏差(负载不平衡)和延迟。
@@ -849,7 +848,7 @@ The above Pod will only run on the node `kube-01`.
849
848
-->
850
849
上面的 Pod 只能运行在节点 `kube-01` 之上。
851
850
852
- <!--
851
+ <!--
853
852
# # Pod topology spread constraints
854
853
855
854
You can use _topology spread constraints_ to control how {{< glossary_tooltip text="Pods" term_id="Pod" >}}
@@ -858,7 +857,7 @@ topology domains that you define. You might do this to improve performance, expe
858
857
overall utilization.
859
858
860
859
Read [Pod topology spread constraints](/docs/concepts/scheduling-eviction/topology-spread-constraints/)
861
- to learn more about how these work.
860
+ to learn more about how these work.
862
861
-->
863
862
# # Pod 拓扑分布约束 {#pod-topology-spread-constraints}
864
863
@@ -877,7 +876,7 @@ to learn more about how these work.
877
876
* Read the design docs for [node affinity](https://git.k8s.io/design-proposals-archive/scheduling/nodeaffinity.md)
878
877
and for [inter-pod affinity/anti-affinity](https://git.k8s.io/design-proposals-archive/scheduling/podaffinity.md).
879
878
* Learn about how the [topology manager](/docs/tasks/administer-cluster/topology-manager/) takes part in node-level
880
- resource allocation decisions.
879
+ resource allocation decisions.
881
880
* Learn how to use [nodeSelector](/docs/tasks/configure-pod-container/assign-pods-nodes/).
882
881
* Learn how to use [affinity and anti-affinity](/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/).
883
882
-->
@@ -888,4 +887,3 @@ to learn more about how these work.
888
887
* 了解[拓扑管理器](/zh-cn/docs/tasks/administer-cluster/topology-manager/)如何参与节点层面资源分配决定。
889
888
* 了解如何使用 [nodeSelector](/zh-cn/docs/tasks/configure-pod-container/assign-pods-nodes/)。
890
889
* 了解如何使用[亲和性和反亲和性](/zh-cn/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/)。
891
-
0 commit comments