github.com/kobeld/docker@v1.12.0-rc1/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 all 17 nodes have been available to receive tasks. 18 19 Sometimes, such as planned maintenance times, you need to set a node to `DRAIN` 20 availabilty. `DRAIN` availabilty 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 ``` 31 $ docker node ls 32 33 ID NAME MEMBERSHIP STATUS AVAILABILITY MANAGER STATUS LEADER 34 1x2bldyhie1cj worker1 Accepted Ready Active 35 1y3zuia1z224i worker2 Accepted Ready Active 36 2p5bfd34mx4op * manager1 Accepted Ready Active Reachable Yes 37 ``` 38 39 2. 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 --update-parallelism 1 redis:3.0.6 44 45 69uh57k8o03jtqj9uvmteodbb 46 ``` 47 48 3. Run `docker service tasks redis` to see how the Swarm manager assigned the 49 tasks to different nodes: 50 51 ``` 52 $ docker service tasks redis 53 54 ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 55 3wfqsgxecktpwoyj2zjcrcn4r redis.1 redis redis:3.0.6 RUNNING 13 minutes RUNNING worker2 56 8lcm041z3v80w0gdkczbot0gg redis.2 redis redis:3.0.6 RUNNING 13 minutes RUNNING worker1 57 d48skceeph9lkz4nbttig1z4a redis.3 redis redis:3.0.6 RUNNING 12 minutes RUNNING manager1 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 4. 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 worker1 69 ``` 70 71 5. Inspect the node to check its availability: 72 73 ``` 74 $ docker node inspect --pretty worker1 75 ID: 1x2bldyhie1cj 76 Hostname: worker1 77 Status: 78 State: READY 79 Availability: DRAIN 80 ...snip... 81 ``` 82 83 The drained node shows `Drain` for `AVAILABILITY`. 84 85 6. Run `docker service tasks redis` to see how the Swarm manager updated the 86 task assignments for the `redis` service: 87 88 ``` 89 ID NAME SERVICE IMAGE LAST STATE DESIRED STATE NODE 90 3wfqsgxecktpwoyj2zjcrcn4r redis.1 redis redis:3.0.6 RUNNING 26 minutes RUNNING worker2 91 ah7o4u5upostw3up1ns9vbqtc redis.2 redis redis:3.0.6 RUNNING 9 minutes RUNNING manager1 92 d48skceeph9lkz4nbttig1z4a redis.3 redis redis:3.0.6 RUNNING 26 minutes RUNNING manager1 93 ``` 94 95 The Swarm manager maintains the desired state by ending the task on a node 96 with `Drain` availability and creating a new task on a node with `Active` 97 availability. 98 99 7. Run `docker node update --availability active <NODE-ID>` to return the 100 drained node to an active state: 101 102 ```bash 103 $ docker node update --availability active worker1 104 worker1 105 ``` 106 107 8. Inspect the node to see the updated state: 108 109 ``` 110 $ docker node inspect --pretty worker1 111 ID: 1x2bldyhie1cj 112 Hostname: worker1 113 Status: 114 State: READY 115 Availability: ACTIVE 116 ...snip... 117 ``` 118 119 When you set the node back to `Active` availability, it can receive new tasks: 120 121 * during a service update to scale up 122 * during a rolling update 123 * when you set another node to `Drain` availability 124 * when a task fails on another active node 125 126 <p style="margin-bottom:300px"> </p>