1 00:00:00,001 --> 00:00:01,901 [No Audio] 2 00:00:01,901 --> 00:00:05,301 Now that we have deployed our Nginx service across 3 00:00:05,301 --> 00:00:07,967 the Swarm cluster successfully, let's think of 4 00:00:07,967 --> 00:00:11,767 some more innovative use cases. For example, what 5 00:00:11,767 --> 00:00:13,767 if I want to take down one of my nodes for 6 00:00:13,767 --> 00:00:17,967 maintenance, or what if one of my nodes actually 7 00:00:17,967 --> 00:00:21,767 goes down. Here, we will test it out. 8 00:00:22,867 --> 00:00:28,401 The safe way to make a node leave the cluster is to drain it, 9 00:00:28,634 --> 00:00:32,366 we can do it with docker node update availability 10 00:00:32,366 --> 00:00:36,034 command, followed by the action and the name of 11 00:00:36,034 --> 00:00:39,434 the node. Here, the command will work like 12 00:00:39,434 --> 00:00:45,601 docker node update --availability flag, drain worker-2, 13 00:00:46,101 --> 00:00:49,467 and what we get is the name of the node as the 14 00:00:49,467 --> 00:00:53,067 confirmation that it has drained out. Still, we 15 00:00:53,067 --> 00:00:57,367 can verify it by typing docker node ls, and we can 16 00:00:57,367 --> 00:01:00,967 see that the status of worker-2 node is still 17 00:01:00,967 --> 00:01:05,134 Ready, but the availability is Drain. Which means 18 00:01:05,233 --> 00:01:08,367 that the node is up, but its availability is 19 00:01:08,367 --> 00:01:10,867 drained, which means that no containers can be 20 00:01:10,867 --> 00:01:13,901 scheduled on it. When we drained the node, the 21 00:01:13,901 --> 00:01:16,767 container or the task scheduled on the node gets 22 00:01:16,767 --> 00:01:19,667 transferred or rescheduled to one of the other 23 00:01:19,667 --> 00:01:25,201 nodes. Let's verify it using docker service ps web-server. 24 00:01:25,201 --> 00:01:28,901 And as you can see, the web-server.3 25 00:01:28,901 --> 00:01:32,301 container has been shifted from worker-2 26 00:01:32,301 --> 00:01:36,234 to manager and it has been running since 42 seconds, 27 00:01:36,234 --> 00:01:40,434 which is about the time when worker-2 was drained. 28 00:01:40,701 --> 00:01:44,467 On the other hand, if we use docker ps 29 00:01:44,467 --> 00:01:47,401 on worker-2 now, which has been drained, 30 00:01:47,467 --> 00:01:51,667 we will see that the container has exited the node 31 00:01:51,767 --> 00:01:55,801 and is now in quite dead state. Now let's remove 32 00:01:55,801 --> 00:01:58,034 this node from cluster whatsoever. 33 00:01:58,734 --> 00:02:03,067 And when we try to do that, we get this error from Docker daemon. 34 00:02:03,334 --> 00:02:08,067 The reason behind that is, the node might be in the 35 00:02:08,067 --> 00:02:11,401 drain condition, but it is still up. Docker is 36 00:02:11,401 --> 00:02:15,201 still serving its API. So we need to make sure 37 00:02:15,201 --> 00:02:18,467 that it leaves the Swarm cluster first, then it 38 00:02:18,467 --> 00:02:21,867 gets removed from the master's list. Let's use 39 00:02:21,867 --> 00:02:25,201 docker swarm leave command from worker-2 node. 40 00:02:25,201 --> 00:02:29,334 Once we do so, we get a pretty clear nod that Node 41 00:02:29,334 --> 00:02:32,267 has left the swarm. If we try to run the same 42 00:02:32,267 --> 00:02:35,601 command again on manager node, we will see that 43 00:02:35,601 --> 00:02:38,434 the worker-2 node has been removed successfully. 44 00:02:38,501 --> 00:02:41,667 We can verify it by listing the nodes again and 45 00:02:41,667 --> 00:02:44,667 what we will find is our cluster made of just two 46 00:02:44,667 --> 00:02:47,167 nodes, manager and worker-1.