|
| 1 | +--- |
| 2 | +title: 仅在某些节点上运行 Pod |
| 3 | +content_type: task |
| 4 | +weight: 30 |
| 5 | +--- |
| 6 | +<!-- |
| 7 | +title: Running Pods on Only Some Nodes |
| 8 | +content_type: task |
| 9 | +weight: 30 |
| 10 | +--> |
| 11 | + |
| 12 | +<!-- overview --> |
| 13 | + |
| 14 | +<!-- |
| 15 | +This page demonstrates how can you run {{<glossary_tooltip term_id="pod" text="Pods">}} on only some {{<glossary_tooltip term_id="node" text="Nodes">}} as part of a {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}} |
| 16 | +--> |
| 17 | +本页演示了你如何能够仅在某些{{<glossary_tooltip term_id="node" text="节点">}}上作为 |
| 18 | +{{<glossary_tooltip term_id="daemonset" text="DaemonSet">}} |
| 19 | +的一部分运行{{<glossary_tooltip term_id="pod" text="Pod">}}。 |
| 20 | + |
| 21 | +## {{% heading "prerequisites" %}} |
| 22 | + |
| 23 | +{{< include "task-tutorial-prereqs.md" >}} |
| 24 | + |
| 25 | +<!-- |
| 26 | +## Running Pods on only some Nodes |
| 27 | +
|
| 28 | +Imagine that you want to run a {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}}, but you only need to run those daemon pods |
| 29 | +on nodes that have local solid state (SSD) storage. For example, the Pod might provide cache service to the |
| 30 | +node, and the cache is only useful when low-latency local storage is available. |
| 31 | +--> |
| 32 | +## 仅在某些节点上运行 Pod {#running-pod-on-some-nodes} |
| 33 | + |
| 34 | +设想一下你想要运行 {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}}, |
| 35 | +但你只需要在配备了本地固态 (SSD) 存储的节点上运行这些守护进程 Pod。 |
| 36 | +例如,Pod 可以向节点提供缓存服务,而缓存仅在低延迟本地存储可用时才有用。 |
| 37 | + |
| 38 | +<!-- |
| 39 | +### Step 1: Add labels to your nodes |
| 40 | +
|
| 41 | +Add the label `ssd=true` to the nodes which have SSDs. |
| 42 | +--> |
| 43 | +### 第 1 步:为节点打标签 |
| 44 | + |
| 45 | +在配有 SSD 的节点上打标签 `ssd=true`。 |
| 46 | + |
| 47 | +```shell |
| 48 | +kubectl label nodes example-node-1 example-node-2 ssd=true |
| 49 | +``` |
| 50 | + |
| 51 | +<!-- |
| 52 | +### Step 2: Create the manifest |
| 53 | +
|
| 54 | +Let's create a {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}} which will provision the daemon pods on the SSD labeled {{<glossary_tooltip term_id="node" text="nodes">}} only. |
| 55 | +
|
| 56 | +Next, use a `nodeSelector` to ensure that the DaemonSet only runs Pods on nodes |
| 57 | +with the `ssd` label set to `"true"`. |
| 58 | +--> |
| 59 | +### 第 2 步:创建清单 |
| 60 | + |
| 61 | +让我们创建一个 {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}}, |
| 62 | +它将仅在打了 SSD 标签的{{<glossary_tooltip term_id="node" text="节点">}}上制备守护进程 Pod。 |
| 63 | + |
| 64 | +接下来,使用 `nodeSelector` 确保 DaemonSet 仅在 `ssd` 标签设为 `"true"` 的节点上运行 Pod。 |
| 65 | + |
| 66 | +{{<codenew file="controllers/daemonset-label-selector.yaml">}} |
| 67 | + |
| 68 | +<!-- |
| 69 | +### Step 3: Create the DaemonSet |
| 70 | +
|
| 71 | +Create the DaemonSet from the manifest by using `kubectl create` or `kubectl apply` |
| 72 | +
|
| 73 | +Let's label another node as `ssd=true`. |
| 74 | +--> |
| 75 | +### 第 3 步:创建 DaemonSet |
| 76 | + |
| 77 | +使用 `kubectl create` 或 `kubectl apply` 从清单创建 DaemonSet。 |
| 78 | + |
| 79 | +让我们为另一个节点打上标签 `ssd=true`。 |
| 80 | + |
| 81 | +```shell |
| 82 | +kubectl label nodes example-node-3 ssd=true |
| 83 | +``` |
| 84 | + |
| 85 | +<!-- |
| 86 | +Labelling the node automatically triggers the control plane (specifically, the DaemonSet controller) |
| 87 | +to run a new daemon pod on that node. |
| 88 | +--> |
| 89 | +节点打上标签后将自动触发控制平面(具体而言是 DaemonSet 控制器)在该节点上运行新的守护进程 Pod。 |
| 90 | + |
| 91 | +```shell |
| 92 | +kubectl get pods -o wide |
| 93 | +``` |
| 94 | + |
| 95 | +<!-- |
| 96 | +The output is similar to: |
| 97 | +--> |
| 98 | +输出类似于: |
| 99 | + |
| 100 | +```console |
| 101 | +NAME READY STATUS RESTARTS AGE IP NODE |
| 102 | +<daemonset-name><some-hash-01> 1/1 Running 0 13s ..... example-node-1 |
| 103 | +<daemonset-name><some-hash-02> 1/1 Running 0 13s ..... example-node-2 |
| 104 | +<daemonset-name><some-hash-03> 1/1 Running 0 5s ..... example-node-3 |
| 105 | +``` |
0 commit comments