|
| 1 | +--- |
| 2 | +title: Running Pods on Only Some Nodes |
| 3 | +content_type: task |
| 4 | +weight: 30 |
| 5 | +--- |
| 6 | +<!-- overview --> |
| 7 | + |
| 8 | +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">}} |
| 9 | + |
| 10 | +## {{% heading "prerequisites" %}} |
| 11 | + |
| 12 | +{{< include "task-tutorial-prereqs.md" >}} |
| 13 | + |
| 14 | +## Running Pods on only some Nodes |
| 15 | + |
| 16 | +Imagine that you want to run a {{<glossary_tooltip term_id="daemonset" text="DaemonSet">}}, but you only need to run those daemon pods |
| 17 | +on nodes that have local solid state (SSD) storage. For example, the Pod might provide cache service to the |
| 18 | +node, and the cache is only useful when low-latency local storage is available. |
| 19 | + |
| 20 | +### Step 1: Add labels to your nodes |
| 21 | + |
| 22 | +Add the label `ssd=true` to the nodes which have SSDs. |
| 23 | + |
| 24 | +```shell |
| 25 | +kubectl label nodes example-node-1 example-node-2 ssd=true |
| 26 | +``` |
| 27 | + |
| 28 | +### Step 2: Create the manifest |
| 29 | + |
| 30 | +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. |
| 31 | + |
| 32 | + |
| 33 | +Next, use a `nodeSelector` to ensure that the DaemonSet only runs Pods on nodes |
| 34 | +with the `ssd` label set to `"true"`. |
| 35 | + |
| 36 | +{{<codenew file="controllers/daemonset-label-selector.yaml">}} |
| 37 | + |
| 38 | +### Step 3: Create the DaemonSet |
| 39 | + |
| 40 | +Create the DaemonSet from the manifest by using `kubectl create` or `kubectl apply` |
| 41 | + |
| 42 | +Let's label another node as `ssd=true`. |
| 43 | + |
| 44 | +```shell |
| 45 | +kubectl label nodes example-node-3 ssd=true |
| 46 | +``` |
| 47 | + |
| 48 | +Labelling the node automatically triggers the control plane (specifically, the DaemonSet controller) |
| 49 | +to run a new daemon pod on that node. |
| 50 | + |
| 51 | +```shell |
| 52 | +kubectl get pods -o wide |
| 53 | +``` |
| 54 | +The output is similar to: |
| 55 | + |
| 56 | +``` |
| 57 | +NAME READY STATUS RESTARTS AGE IP NODE |
| 58 | +<daemonset-name><some-hash-01> 1/1 Running 0 13s ..... example-node-1 |
| 59 | +<daemonset-name><some-hash-02> 1/1 Running 0 13s ..... example-node-2 |
| 60 | +<daemonset-name><some-hash-03> 1/1 Running 0 5s ..... example-node-3 |
| 61 | +``` |
0 commit comments