1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/docs/swarm/swarm-tutorial/drain-node.md
Stephen J Day 0aa4e1e689
cli: docker service|node|stack ps instead of tasks
Rather than conflict with the unexposed task model, change the names of
the object-oriented task display to `docker <object> ps`. The command
works identically to `docker service tasks`. This change is superficial.

This provides a more sensical docker experience while not trampling on
the task model that may be introduced as a top-level command at a later
date.

The following is an example of the display using `docker service ps`
with a service named `condescending_cori`:

```
$ docker service ps condescending_cori
ID                         NAME                  SERVICE             IMAGE   LAST STATE              DESIRED STATE  NODE
e2cd9vqb62qjk38lw65uoffd2  condescending_cori.1  condescending_cori  alpine  Running 13 minutes ago  Running        6c6d232a5d0e
```

The following shows the output for the node on which the command is
running:

```console
$ docker node ps self
ID                         NAME                  SERVICE             IMAGE   LAST STATE              DESIRED STATE  NODE
b1tpbi43k1ibevg2e94bmqo0s  mad_kalam.1           mad_kalam           apline  Accepted 2 seconds ago  Accepted       6c6d232a5d0e
e2cd9vqb62qjk38lw65uoffd2  condescending_cori.1  condescending_cori  alpine  Running 12 minutes ago  Running        6c6d232a5d0e
4x609m5o0qyn0kgpzvf0ad8x5  furious_davinci.1     furious_davinci     redis   Running 32 minutes ago  Running        6c6d232a5d0e
```

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-07-27 11:06:42 -07:00

4.2 KiB

Drain a node on the swarm

In earlier steps of the tutorial, all the nodes have been running with ACTIVE availability. The swarm manager can assign tasks to any ACTIVE node, so up to now all nodes have been available to receive tasks.

Sometimes, such as planned maintenance times, you need to set a node to DRAIN availability. DRAIN 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 ACTIVE availability.

  1. 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 manager1.

  2. Verify that all your nodes are actively available.

    $ docker node ls
    
    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    1bcef6utixb0l0ca7gxuivsj0    worker2   Ready   Active
    38ciaotwjuritcdtn9npbnkuz    worker1   Ready   Active
    e216jshn25ckzbvmwlnh5jr3g *  manager1  Ready   Active        Leader
    
  3. If you aren't still running the redis service from the rolling update tutorial, start it now:

    $ docker service create --replicas 3 --name redis --update-delay 10s redis:3.0.6
    
    c5uo6kdmzpon37mgj9mwglcfw
    
  4. Run docker service ps redis to see how the Swarm manager assigned the tasks to different nodes:

    $ docker service ps redis
    
    ID                         NAME     SERVICE  IMAGE        LAST STATE          DESIRED STATE  NODE
    7q92v0nr1hcgts2amcjyqg3pq  redis.1  redis    redis:3.0.6  Running 26 seconds  Running        manager1
    7h2l8h3q3wqy5f66hlv9ddmi6  redis.2  redis    redis:3.0.6  Running 26 seconds  Running        worker1
    9bg7cezvedmkgg6c8yzvbhwsd  redis.3  redis    redis:3.0.6  Running 26 seconds  Running        worker2
    

    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.

  5. Run docker node update --availability drain <NODE-ID> to drain a node that had a task assigned to it:

    docker node update --availability drain worker1
    
    worker1
    
  6. Inspect the node to check its availability:

    $ docker node inspect --pretty worker1
    
    ID:			38ciaotwjuritcdtn9npbnkuz
    Hostname:		worker1
    Status:
     State:			Ready
     Availability:		Drain
    ...snip...
    

    The drained node shows Drain for AVAILABILITY.

  7. Run docker service ps redis to see how the Swarm manager updated the task assignments for the redis service:

    $ docker service ps redis
    
    ID                         NAME     SERVICE  IMAGE        LAST STATE              DESIRED STATE  NODE
    7q92v0nr1hcgts2amcjyqg3pq  redis.1  redis    redis:3.0.6  Running 4 minutes       Running        manager1
    b4hovzed7id8irg1to42egue8  redis.2  redis    redis:3.0.6  Running About a minute  Running        worker2
    9bg7cezvedmkgg6c8yzvbhwsd  redis.3  redis    redis:3.0.6  Running 4 minutes       Running        worker2
    

    The Swarm manager maintains the desired state by ending the task on a node with Drain availability and creating a new task on a node with Active availability.

  8. Run docker node update --availability active <NODE-ID> to return the drained node to an active state:

    $ docker node update --availability active worker1
    
    worker1
    
  9. Inspect the node to see the updated state:

    $ docker node inspect --pretty worker1
    
    ID:			38ciaotwjuritcdtn9npbnkuz
    Hostname:		worker1
    Status:
     State:			Ready
     Availability:		Active
    

...snip...


When you set the node back to `Active` availability, it can receive new tasks:

* during a service update to scale up
* during a rolling update
* when you set another node to `Drain` availability
* when a task fails on another active node