I created a docker swarm cluster with 4 nodes out of it 2 is swarm manager (swarm supports multiple manager) I understand if the current manager node goes down then the second manager takes the role of being the swarm manager.
In my case I am firing the rest call to the swarm manager for creating the services with replicas and so on.
At some point if this manager goes down and the second manager becomes manager how do I know ??
Is there any way it gives notified that the particular node is a manager dynamically ??
Please give me the clarification on this ??
When you run a swarm of Docker Engines, manager nodes are the key components for managing the swarm and storing the swarm state. It is important to understand some key features of manager nodes to properly deploy and maintain the swarm.
When the Docker Engine runs in swarm mode, manager nodes implement the Raft Consensus Algorithm to manage the global cluster state.
Worker nodes You can create a swarm of one manager node, but you cannot have a worker node without at least one manager node. By default, all managers are also workers.
The quick way to (manually) know if the manager changed is through the CLI:
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
46aqrk4e473hjbt745z53cr3t node-5 Ready Active Reachable
61pi3d91s0w3b90ijw3deeb2q node-4 Ready Active Reachable
a5b2m3oghd48m8eu391pefq5u node-3 Ready Active
e7p8btxeu3ioshyuj6lxiv6g0 node-2 Ready Active
ehkv3bcimagdese79dn78otj5 * node-1 Ready Active Leader
You can find out which Manager is the current Leader under the MANAGER STATUS
column.
You can also check individually on each node formatting with the Leader
field, for example:
$ docker node inspect <id-node> --format "{{ .ManagerStatus.Leader }}"
true
You can also check which one of the manager is the leader programmatically. The docker remote API exposes a Nodes API endpoint that you can use to list nodes.
You can provide a filter as a parameter which takes the key=value
form.
You can use that filter to list manager nodes only (with role=manager
), then you can parse and filter the JSON output to keep the node whose Leader
field is set at true
(under ManagerStatus
).
Unfortunately there is no leader
filter (yet) but I assume that this could be a valid enhancement to propose on the swarmkit issue tracker.
There are no events stream on docker swarm mode yet (this is tracked by this issue on the swarmkit repository). I imagine that in the future, an event will trigger on Leader switch and you will be dynamically notified of the new leader if you are listening to these events (for example if you have a special setup and want to dynamically update entries in consul, nginx or Interlock).
To find out manager nodes, run docker info It lists out current node address as well as manager addresses, among many other info.
The command docker node ls isn't very useful here as it works only from a manager node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With