github.com/portworx/docker@v1.12.1/docs/swarm/swarm-tutorial/drain-node.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Drain a node" 4 description = "Drain nodes on the swarm" 5 keywords = ["tutorial, cluster management, swarm, service, drain"] 6 [menu.main] 7 identifier="swarm-tutorial-drain-node" 8 parent="swarm-tutorial" 9 weight=21 10 +++ 11 <![end-metadata]--> 12 13 # Drain a node on the swarm 14 15 In earlier steps of the tutorial, all the nodes have been running with `ACTIVE` 16 availability. The swarm manager can assign tasks to any `ACTIVE` node, so up to 17 now all nodes have been available to receive tasks. 18 19 Sometimes, such as planned maintenance times, you need to set a node to `DRAIN` 20 availability. `DRAIN` availability prevents a node from receiving new tasks 21 from the swarm manager. It also means the manager stops tasks running on the 22 node and launches replica tasks on a node with `ACTIVE` availability. 23 24 1. If you haven't already, open a terminal and ssh into the machine where you 25 run your manager node. For example, the tutorial uses a machine named 26 `manager1`. 27 28 2. Verify that all your nodes are actively available. 29 30 ```bash 31 $ docker node ls 32 33 ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 34 1bcef6utixb0l0ca7gxuivsj0 worker2 Ready Active 35 38ciaotwjuritcdtn9npbnkuz worker1 Ready Active 36 e216jshn25ckzbvmwlnh5jr3g * manager1 Ready Active Leader 37 ``` 38 39 3. If you aren't still running the `redis` service from the [rolling 40 update](rolling-update.md) tutorial, start it now: 41 42 ```bash 43 $ docker service create --replicas 3 --name redis --update-delay 10s redis:3.0.6 44 45 c5uo6kdmzpon37mgj9mwglcfw 46 ``` 47 48 4. Run `docker service ps redis` to see how the swarm manager assigned the 49 tasks to different nodes: 50 51 ```bash 52 $ docker service ps redis 53 54 ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 55 7q92v0nr1hcgts2amcjyqg3pq redis.1 redis redis:3.0.6 Running 26 seconds Running manager1 56 7h2l8h3q3wqy5f66hlv9ddmi6 redis.2 redis redis:3.0.6 Running 26 seconds Running worker1 57 9bg7cezvedmkgg6c8yzvbhwsd redis.3 redis redis:3.0.6 Running 26 seconds Running worker2 58 ``` 59 60 In this case the swarm manager distributed one task to each node. You may 61 see the tasks distributed differently among the nodes in your environment. 62 63 5. Run `docker node update --availability drain <NODE-ID>` to drain a node that 64 had a task assigned to it: 65 66 ```bash 67 docker node update --availability drain worker1 68 69 worker1 70 ``` 71 72 6. Inspect the node to check its availability: 73 74 ```bash 75 $ docker node inspect --pretty worker1 76 77 ID: 38ciaotwjuritcdtn9npbnkuz 78 Hostname: worker1 79 Status: 80 State: Ready 81 Availability: Drain 82 ...snip... 83 ``` 84 85 The drained node shows `Drain` for `AVAILABILITY`. 86 87 7. Run `docker service ps redis` to see how the swarm manager updated the 88 task assignments for the `redis` service: 89 90 ```bash 91 $ docker service ps redis 92 93 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR 94 7q92v0nr1hcgts2amcjyqg3pq redis.1 redis:3.0.6 manager1 Running Running 4 minutes 95 b4hovzed7id8irg1to42egue8 redis.2 redis:3.0.6 worker2 Running Running About a minute 96 7h2l8h3q3wqy5f66hlv9ddmi6 \_ redis.2 redis:3.0.6 worker1 Shutdown Shutdown 2 minutes ago 97 9bg7cezvedmkgg6c8yzvbhwsd redis.3 redis:3.0.6 worker2 Running Running 4 minutes 98 ``` 99 100 The Swarm manager maintains the desired state by ending the task on a node 101 with `Drain` availability and creating a new task on a node with `Active` 102 availability. 103 104 8. Run `docker node update --availability active <NODE-ID>` to return the 105 drained node to an active state: 106 107 ```bash 108 $ docker node update --availability active worker1 109 110 worker1 111 ``` 112 113 9. Inspect the node to see the updated state: 114 115 ```bash 116 $ docker node inspect --pretty worker1 117 118 ID: 38ciaotwjuritcdtn9npbnkuz 119 Hostname: worker1 120 Status: 121 State: Ready 122 Availability: Active 123 ...snip... 124 ``` 125 126 When you set the node back to `Active` availability, it can receive new tasks: 127 128 * during a service update to scale up 129 * during a rolling update 130 * when you set another node to `Drain` availability 131 * when a task fails on another active node