- [Instructor] When you take multiple Docker nodes,
and you initialize swarm across those nodes,
creating the swarm cluster,
you have the concept of manager nodes and worker nodes.
It's the manager nodes that have to ensure
that the cluster's state is intact,
that the services that you have deployed
across the cluster remain highly scalable,
and highly available, and it's the managers
that have to agree on any proposed updates to the cluster,
including node additions or removals.
For those swarm cluster managers
to be able to make those types of decisions,
and ensure that the cluster's state is always healthy,
they have to have something called quorum.
So a quorum is a majority of managers.
To ensure that quorum is achieved in the cluster,
swarm managers use something
called the Raft Consensus Algorithm.
And here in the Docker documentation,
they go into great detail about how quorum
is achieved in the cluster.
In fact there are some very important equations
that you should be aware of, if you're preparing
for the Docker Certified Associate exam,
or if you're deploying larger Docker swarm clusters.
The Docker documentation has a number of different charts,
like the one you see here, that show that for example,
if you just have a swarm size of two nodes,
you require a minimum of two nodes for majority,
so you have zero fault tolerance,
even in a two node cluster.
In order to have high availability and fault tolerance
in your Docker swarm cluster,
you need a minimum of three swarm managers in that cluster.
And the interesting trend to note here
is that it's always better to have
an odd number of swarm managers,
instead of an even number of swarm managers.
For example if you have four swarm managers
instead of three swarm managers,
you still just have fault tolerance of one,
because of how these equations work.
The same thing happens for example
if you have eight swarm managers instead of seven,
you can still only lose three swarm managers.
The Docker documentation has another nice resource here
that actually breaks out this equation,
and it shows you that Raft tolerates
N minus one divided by two failures,
and requires a majority of quorum
of N divided by two plus one members,
to agree on values proposed to the cluster.
And they go on to say that this means for example
if you have a cluster of five managers,
if three nodes are unavailable,
the system cannot process anymore requests
to schedule additional tasks.
So even if you have five managers, and you lose three,
and you have two remaining, your swarm cluster
won't be able to achieve quorum,
and because of that, no decisions can be made,
and the cluster is effectively down.
In this document, Docker points
to a very interesting resource
called the Raft Consensus Algorithm.
This takes us to a whole other website
called The Secret Lives of Data,
where they go into great detail
on exactly how the Raft Consensus Algorithm works,
and they explain it all visually.
So if you're interested in that, check it out.
It's not required for the Docker Certified Associate,
and it's not even really required
when it comes to administering a Docker swarm cluster.
But it is fascinating how behind the scenes
the quorum consensus is reached.
Back here in this Docker document,
I want to point out one other chart
that's very interesting in here.
So if you're going to have multiple availability zones,
for example two different data centers in the same city,
or two different data centers
even spread across the same continent,
you need to ensure that your swarm cluster
can still maintain quorum,
and this document talks about exactly how to calculate that.
And this is something that you should read up on,
in preparation for the Docker Certified Associate exam.
Something else to note, is that you can run
manager-only nodes, and the command to do this,
is docker node update, dash dash availability,
space, drain, space, node.
And what this does, is it removes
all the workloads from a single Docker node,
and effectively making that node a manager-only node.
That's because by default, managers also run workloads,
and by draining the workloads with this command,
you can ensure that you have manager nodes available
to make critical decisions in the cluster,
and to ensure that quorum is always able to be achieved,
by preventing workloads from running on those managers,
which could perhaps starve the manager node for resources.
For more information on Docker swarm clusters,
monitoring swarm health,
and troubleshooting swarm clusters,
check out the Docker documentation covering Docker swarm.