Etcd: how can I know which node is leader etcd 3.3.1?

Created on 9 Mar 2018  路  3Comments  路  Source: etcd-io/etcd

3 nodes etcd cluster
etcd version 3.1.9 can shows that
isLeader=false or isLeader=true,when I run etcdcrt member list.

etcd -version
etcd Version: 3.1.9
Git SHA: 0f4a535
Go Version: go1.7.4
Go OS/Arch: linux/amd64

etcdctl member list
29cae73abe8480e0: name=infra3 peerURLs=http://192.168.2.188:2380 clientURLs=http://192.168.2.188:2379 isLeader=false
ddfd1a6f3be67384: name=infra1 peerURLs=http://192.168.2.186:2380 clientURLs=http://192.168.2.186:2379 isLeader=true
fd49f5e3ec73b0d2: name=infra2 peerURLs=http://192.168.2.187:2380 clientURLs=http://192.168.2.187:2379 isLeader=false

but etcd version 3.2.x and 3.3.1 doesnot show this
So how do I know which one is the leader?

etcd --version
etcd Version: 3.3.1
Git SHA: 28f3f26c0
Go Version: go1.9.4
Go OS/Arch: linux/amd64

etcdctl member list
1114740c6d5f9f2, started, etcd1, https://192.168.9.186:2380, https://192.168.9.186:2379
4d19012a3d971b72, started, etcd2, https://192.168.9.187:2380, https://192.168.9.187:2379
e30c8a56457f8a6a, started, etcd3, https://192.168.9.188:2380, https://192.168.9.188:2379

you can see that I donot use TLS in version 3.1 and use TLS in version 3.3.1
Is this about etcd version,using TSL or not, API version or any other reason?
I also want to know which one is the leader.
any other command can show the leader?

arequestion

Most helpful comment

The output of the member commands depend on ETCDCTL_API.

ETCDCTL_API=3 ./bin/etcdctl member list
ade526d28b1f92f7, started, etcd1, http://etcd1:2380, http://127.0.0.1:12379
cf1d15c5d194b5c9, started, etcd0, http://etcd0:2380, http://127.0.0.1:2379
d282ac2ce600c1ce, started, etcd2, http://etcd2:2380, http://127.0.0.2:22379
ETCDCTL_API=2 ./bin/etcdctl member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://127.0.0.1:12379 isLeader=true
cf1d15c5d194b5c9: name=etcd0 peerURLs=http://etcd0:2380 clientURLs=http://127.0.0.1:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://127.0.0.2:22379 isLeader=false

The endpoint status command also shows leader status.

ETCDCTL_API=3 etcdctl -w table --endpoints=etcd1:2379,etcd2:2379,etcd0:2379 endpoint status
+------------+------------------+---------+---------+-----------+-----------+------------+
|  ENDPOINT  |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------+------------------+---------+---------+-----------+-----------+------------+
| etcd1:2379 | ade526d28b1f92f7 |   3.3.1 |  467 MB |      true |        27 |    6289071 |
| etcd2:2379 | d282ac2ce600c1ce |   3.3.1 |  467 MB |     false |        27 |    6289071 |
| etcd0:2379 | cf1d15c5d194b5c9 |   3.3.1 |  467 MB |     false |        27 |    6289071 |
+------------+------------------+---------+---------+-----------+-----------+------------+

All 3 comments

The output of the member commands depend on ETCDCTL_API.

ETCDCTL_API=3 ./bin/etcdctl member list
ade526d28b1f92f7, started, etcd1, http://etcd1:2380, http://127.0.0.1:12379
cf1d15c5d194b5c9, started, etcd0, http://etcd0:2380, http://127.0.0.1:2379
d282ac2ce600c1ce, started, etcd2, http://etcd2:2380, http://127.0.0.2:22379
ETCDCTL_API=2 ./bin/etcdctl member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://127.0.0.1:12379 isLeader=true
cf1d15c5d194b5c9: name=etcd0 peerURLs=http://etcd0:2380 clientURLs=http://127.0.0.1:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://127.0.0.2:22379 isLeader=false

The endpoint status command also shows leader status.

ETCDCTL_API=3 etcdctl -w table --endpoints=etcd1:2379,etcd2:2379,etcd0:2379 endpoint status
+------------+------------------+---------+---------+-----------+-----------+------------+
|  ENDPOINT  |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+------------+------------------+---------+---------+-----------+-----------+------------+
| etcd1:2379 | ade526d28b1f92f7 |   3.3.1 |  467 MB |      true |        27 |    6289071 |
| etcd2:2379 | d282ac2ce600c1ce |   3.3.1 |  467 MB |     false |        27 |    6289071 |
| etcd0:2379 | cf1d15c5d194b5c9 |   3.3.1 |  467 MB |     false |        27 |    6289071 |
+------------+------------------+---------+---------+-----------+-----------+------------+

I will close the issue and consider it addressed

It wokrs like what you do.

There's also the --cluster flag which will use all endpoints from the cluster member list, without you having to specify each individually using the --endpoints flag.

$ ETCDCTL_API=3 etcdctl endpoint status --cluster -w table
+----------------------------+------------------+---------+---------+-----------+-----------+------------+
|          ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+----------------------------+------------------+---------+---------+-----------+-----------+------------+
| http://192.168.144.11:2379 | 939e974d80fa7dd5 |  3.3.13 |   20 kB |      true |         2 |         12 |
| http://192.168.144.13:2379 | bd04095b49eb535c |  3.3.13 |   20 kB |     false |         2 |         12 |
| http://192.168.144.12:2379 | cf7585769b2ce974 |  3.3.13 |   20 kB |     false |         2 |         12 |
+----------------------------+------------------+---------+---------+-----------+-----------+------------+

Was this page helpful?
0 / 5 - 0 ratings