Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which node is the currently the manager node in docker swarm in a multiple swarm manager cluster?

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 ??

like image 974
Vishnu Ranganathan Avatar asked Oct 25 '16 17:10

Vishnu Ranganathan


People also ask

What is manager node in docker Swarm?

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.

Which algorithm is used for managing manager nodes in docker swarm cluster?

When the Docker Engine runs in swarm mode, manager nodes implement the Raft Consensus Algorithm to manage the global cluster state.

How many manager node requires have a worker node?

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.


2 Answers

Using the CLI

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

Using the Docker Remote API

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).

like image 141
abronan Avatar answered Oct 11 '22 13:10

abronan


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.

like image 42
theSushil Avatar answered Oct 11 '22 15:10

theSushil