github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/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  advisory="rc"
     7  [menu.main]
     8  identifier="swarm-tutorial-drain-node"
     9  parent="swarm-tutorial"
    10  weight=21
    11  +++
    12  <![end-metadata]-->
    13  
    14  # Drain a node on the swarm
    15  
    16  In earlier steps of the tutorial, all the nodes have been running with `ACTIVE`
    17  availability. The swarm manager can assign tasks to any `ACTIVE` node, so up to
    18  now all nodes have been available to receive tasks.
    19  
    20  Sometimes, such as planned maintenance times, you need to set a node to `DRAIN`
    21  availability. `DRAIN` availability  prevents a node from receiving new tasks
    22  from the swarm manager. It also means the manager stops tasks running on the
    23  node and launches replica tasks on a node with `ACTIVE` availability.
    24  
    25  1. If you haven't already, open a terminal and ssh into the machine where you
    26  run your manager node. For example, the tutorial uses a machine named
    27  `manager1`.
    28  
    29  2. Verify that all your nodes are actively available.
    30  
    31      ```bash
    32      $ docker node ls
    33  
    34      ID                           NAME      MEMBERSHIP  STATUS  AVAILABILITY     MANAGER STATUS  LEADER
    35      1bcef6utixb0l0ca7gxuivsj0    worker2   Accepted    Ready   Active
    36      38ciaotwjuritcdtn9npbnkuz    worker1   Accepted    Ready   Active
    37      e216jshn25ckzbvmwlnh5jr3g *  manager1  Accepted    Ready   Active        Reachable       Yes
    38      ```
    39  
    40  2. If you aren't still running the `redis` service from the [rolling
    41  update](rolling-update.md) tutorial, start it now:
    42  
    43      ```bash
    44      $ docker service create --replicas 3 --name redis --update-delay 10s --update-parallelism 1 redis:3.0.6
    45  
    46      c5uo6kdmzpon37mgj9mwglcfw
    47      ```
    48  
    49  3. Run `docker service tasks redis` to see how the Swarm manager assigned the
    50  tasks to different nodes:
    51  
    52      ```bash
    53      $ docker service tasks redis
    54  
    55      ID                         NAME     SERVICE  IMAGE        LAST STATE          DESIRED STATE  NODE
    56      7q92v0nr1hcgts2amcjyqg3pq  redis.1  redis    redis:3.0.6  Running 26 seconds  Running        manager1
    57      7h2l8h3q3wqy5f66hlv9ddmi6  redis.2  redis    redis:3.0.6  Running 26 seconds  Running        worker1
    58      9bg7cezvedmkgg6c8yzvbhwsd  redis.3  redis    redis:3.0.6  Running 26 seconds  Running        worker2
    59      ```
    60  
    61      In this case the swarm manager distributed one task to each node. You may
    62      see the tasks distributed differently among the nodes in your environment.
    63  
    64  4. Run `docker node update --availability drain <NODE-ID>` to drain a node that
    65  had a task assigned to it:
    66  
    67      ```bash
    68      docker node update --availability drain worker1
    69  
    70      worker1
    71      ```
    72  
    73  5. Inspect the node to check its availability:
    74  
    75      ```bash
    76      $ docker node inspect --pretty worker1
    77  
    78      ID:			38ciaotwjuritcdtn9npbnkuz
    79      Hostname:		worker1
    80      Status:
    81       State:			Ready
    82       Availability:		Drain
    83      ...snip...
    84      ```
    85  
    86      The drained node shows `Drain` for `AVAILABILITY`.
    87  
    88  6. Run `docker service tasks redis` to see how the Swarm manager updated the
    89  task assignments for the `redis` service:
    90  
    91      ```bash
    92      $ docker service tasks redis
    93  
    94      ID                         NAME     SERVICE  IMAGE        LAST STATE              DESIRED STATE  NODE
    95      7q92v0nr1hcgts2amcjyqg3pq  redis.1  redis    redis:3.0.6  Running 4 minutes       Running        manager1
    96      b4hovzed7id8irg1to42egue8  redis.2  redis    redis:3.0.6  Running About a minute  Running        worker2
    97      9bg7cezvedmkgg6c8yzvbhwsd  redis.3  redis    redis:3.0.6  Running 4 minutes       Running        worker2
    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  7. 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  8. 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