[No Audio]
Now that we have deployed our Nginx service across
the Swarm cluster successfully, let's think of
some more innovative use cases. For example, what
if I want to take down one of my nodes for
maintenance, or what if one of my nodes actually
goes down. Here, we will test it out.
The safe way to make a node leave the cluster is to drain it,
we can do it with docker node update availability
command, followed by the action and the name of
the node. Here, the command will work like
docker node update --availability flag, drain worker-2,
and what we get is the name of the node as the
confirmation that it has drained out. Still, we
can verify it by typing docker node ls, and we can
see that the status of worker-2 node is still
Ready, but the availability is Drain. Which means
that the node is up, but its availability is
drained, which means that no containers can be
scheduled on it. When we drained the node, the
container or the task scheduled on the node gets
transferred or rescheduled to one of the other
nodes. Let's verify it using docker service ps web-server.
And as you can see, the web-server.3
container has been shifted from worker-2
to manager and it has been running since 42 seconds,
which is about the time when worker-2 was drained.
On the other hand, if we use docker ps
on worker-2 now, which has been drained,
we will see that the container has exited the node
and is now in quite dead state. Now let's remove
this node from cluster whatsoever.
And when we try to do that, we get this error from Docker daemon.
The reason behind that is, the node might be in the
drain condition, but it is still up. Docker is
still serving its API. So we need to make sure
that it leaves the Swarm cluster first, then it
gets removed from the master's list. Let's use
docker swarm leave command from worker-2 node.
Once we do so, we get a pretty clear nod that Node
has left the swarm. If we try to run the same
command again on manager node, we will see that
the worker-2 node has been removed successfully.
We can verify it by listing the nodes again and
what we will find is our cluster made of just two
nodes, manager and worker-1.