summaryrefslogtreecommitdiff
path: root/devdocs/docker/engine%2Fswarm%2Fswarm-tutorial%2Fdrain-node%2Findex.html
blob: 965efcb0fedd2c80892411548d9dbbc255033bd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<h1>Drain a node on the swarm</h1>

<p>In earlier steps of the tutorial, all the nodes have been running with <code class="language-plaintext highlighter-rouge">ACTIVE</code> availability. The swarm manager can assign tasks to any <code class="language-plaintext highlighter-rouge">ACTIVE</code> node, so up to now all nodes have been available to receive tasks.</p> <p>Sometimes, such as planned maintenance times, you need to set a node to <code class="language-plaintext highlighter-rouge">DRAIN</code> availability. <code class="language-plaintext highlighter-rouge">DRAIN</code> availability prevents a node from receiving new tasks from the swarm manager. It also means the manager stops tasks running on the node and launches replica tasks on a node with <code class="language-plaintext highlighter-rouge">ACTIVE</code> availability.</p> <blockquote class="important"> <p><strong>Important</strong>: Setting a node to <code class="language-plaintext highlighter-rouge">DRAIN</code> does not remove standalone containers from that node, such as those created with <code class="language-plaintext highlighter-rouge">docker run</code>, <code class="language-plaintext highlighter-rouge">docker-compose up</code>, or the Docker Engine API. A node’s status, including <code class="language-plaintext highlighter-rouge">DRAIN</code>, only affects the node’s ability to schedule swarm service workloads.</p> </blockquote> <ol> <li> <p>If you haven’t already, open a terminal and ssh into the machine where you run your manager node. For example, the tutorial uses a machine named <code class="language-plaintext highlighter-rouge">manager1</code>.</p> </li> <li> <p>Verify that all your nodes are actively available.</p> <div class="highlight"><pre class="highlight" data-language="">$ docker node ls

ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0    worker2   Ready   Active
38ciaotwjuritcdtn9npbnkuz    worker1   Ready   Active
e216jshn25ckzbvmwlnh5jr3g *  manager1  Ready   Active        Leader
</pre></div>  </li> <li> <p>If you aren’t still running the <code class="language-plaintext highlighter-rouge">redis</code> service from the <a href="../rolling-update/index">rolling update</a> tutorial, start it now:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker service create --replicas 3 --name redis --update-delay 10s redis:3.0.6

c5uo6kdmzpon37mgj9mwglcfw
</pre></div>  </li> <li> <p>Run <code class="language-plaintext highlighter-rouge">docker service ps redis</code> to see how the swarm manager assigned the tasks to different nodes:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker service ps redis

NAME                               IMAGE        NODE     DESIRED STATE  CURRENT STATE
redis.1.7q92v0nr1hcgts2amcjyqg3pq  redis:3.0.6  manager1 Running        Running 26 seconds
redis.2.7h2l8h3q3wqy5f66hlv9ddmi6  redis:3.0.6  worker1  Running        Running 26 seconds
redis.3.9bg7cezvedmkgg6c8yzvbhwsd  redis:3.0.6  worker2  Running        Running 26 seconds
</pre></div>  <p>In this case the swarm manager distributed one task to each node. You may see the tasks distributed differently among the nodes in your environment.</p> </li> <li> <p>Run <code class="language-plaintext highlighter-rouge">docker node update --availability drain &lt;NODE-ID&gt;</code> to drain a node that had a task assigned to it:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker node update --availability drain worker1

worker1
</pre></div>  </li> <li> <p>Inspect the node to check its availability:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker node inspect --pretty worker1

ID:			38ciaotwjuritcdtn9npbnkuz
Hostname:		worker1
Status:
 State:			Ready
 Availability:		Drain
...snip...
</pre></div>  <p>The drained node shows <code class="language-plaintext highlighter-rouge">Drain</code> for <code class="language-plaintext highlighter-rouge">AVAILABILITY</code>.</p> </li> <li> <p>Run <code class="language-plaintext highlighter-rouge">docker service ps redis</code> to see how the swarm manager updated the task assignments for the <code class="language-plaintext highlighter-rouge">redis</code> service:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker service ps redis

NAME                                    IMAGE        NODE      DESIRED STATE  CURRENT STATE           ERROR
redis.1.7q92v0nr1hcgts2amcjyqg3pq       redis:3.0.6  manager1  Running        Running 4 minutes
redis.2.b4hovzed7id8irg1to42egue8       redis:3.0.6  worker2   Running        Running About a minute
 \_ redis.2.7h2l8h3q3wqy5f66hlv9ddmi6   redis:3.0.6  worker1   Shutdown       Shutdown 2 minutes ago
redis.3.9bg7cezvedmkgg6c8yzvbhwsd       redis:3.0.6  worker2   Running        Running 4 minutes
</pre></div>  <p>The swarm manager maintains the desired state by ending the task on a node with <code class="language-plaintext highlighter-rouge">Drain</code> availability and creating a new task on a node with <code class="language-plaintext highlighter-rouge">Active</code> availability.</p> </li> <li> <p>Run <code class="language-plaintext highlighter-rouge">docker node update --availability active &lt;NODE-ID&gt;</code> to return the drained node to an active state:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker node update --availability active worker1

worker1
</pre></div>  </li> <li> <p>Inspect the node to see the updated state:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker node inspect --pretty worker1

ID:			38ciaotwjuritcdtn9npbnkuz
Hostname:		worker1
Status:
 State:			Ready
 Availability:		Active
...snip...
</pre></div>  <p>When you set the node back to <code class="language-plaintext highlighter-rouge">Active</code> availability, it can receive new tasks:</p> <ul> <li>during a service update to scale up</li> <li>during a rolling update</li> <li>when you set another node to <code class="language-plaintext highlighter-rouge">Drain</code> availability</li> <li>when a task fails on another active node</li> </ul> </li> </ol> <h2 id="whats-next">What’s next?</h2> <p>Learn how to <a href="../../ingress/index">use a swarm mode routing mesh</a>.</p> 
<p><a href="https://docs.docker.com/search/?q=tutorial">tutorial</a>, <a href="https://docs.docker.com/search/?q=cluster%20management">cluster management</a>, <a href="https://docs.docker.com/search/?q=swarm">swarm</a>, <a href="https://docs.docker.com/search/?q=service">service</a>, <a href="https://docs.docker.com/search/?q=drain">drain</a></p>
<div class="_attribution">
  <p class="_attribution-p">
    &copy; 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
    <a href="https://docs.docker.com/engine/swarm/swarm-tutorial/drain-node/" class="_attribution-link">https://docs.docker.com/engine/swarm/swarm-tutorial/drain-node/</a>
  </p>
</div>