Is there a way to know the current leader in a Kubernetes HA cluster?

7,301 views
Skip to first unread message

Qian Zhang

unread,
Feb 14, 2017, 8:27:50 AM2/14/17
to Kubernetes user discussion and Q&A
Hi,

I have a Kubernetes HA cluster which consists of 3 master nodes, each of them has kube-apiserver, kube-scheduler and kube-controller-manager running, and kube-scheduler and kube-controller-manager are started with the option "--leader-elect", my question is, is there a way to tell the current leader of kube-scheduler/kube-controller-manager? E.g., a Kubernetes API to get such info? Or directly get it from etcd?


Thanks,
Qian Zhang

Jerzy Szczepkowski

unread,
Feb 14, 2017, 9:18:54 AM2/14/17
to kubernet...@googlegroups.com
You can get it from endpoints resource. The endpoint should have an annotation pointing to the leader.

$ kubectl get endpoints kube-controller-manager --namespace=kube-system  -o yaml

apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"kubernetes-master","leaseDurationSeconds":15,"acquireTime":"2017-02-14T14:05:57Z","renewTime":"2017-02-14T14:14:42Z","leaderTransitions":0}'
...


Regards,
Jerzy

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Qian Zhang

unread,
Feb 15, 2017, 3:51:35 AM2/15/17
to kubernet...@googlegroups.com
Thanks Jerzy!


Thanks,
Qian Zhang

--
You received this message because you are subscribed to a topic in the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kubernetes-users/5Zf3WmXuOco/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kubernetes-users+unsubscribe@googlegroups.com.

Junaid Subhani

unread,
Jun 30, 2017, 3:24:20 PM6/30/17
to Kubernetes user discussion and Q&A
Hello Jerzy ,

Is there a much more direct way to get just the value of holderIdentity ?

My request :

This gives me :

{ "kind": "Endpoints", "apiVersion": "v1", "metadata": { "name": "kube-controller-manager", "namespace": "kube-system", "selfLink": "/api/v1/namespaces/kube-system/endpoints/kube-controller-manager", "uid": "89e09aae-5dc6-11e7-89c1-0050569b569d", "resourceVersion": "19152", "creationTimestamp": "2017-06-30T19:01:35Z", "annotations": { "control-plane.alpha.kubernetes.io/leader": "{\"holderIdentity\":\"master2\",\"leaseDurationSeconds\":15,\"acquireTime\":\"2017-06-30T19:01:35Z\",\"renewTime\":\"2017-06-30T19:18:01Z\",\"leaderTransitions\":0}" } }, "subsets": [] }

I basically need to configure HAProxy based on the value of holderIdentity



On Tuesday, 14 February 2017 09:18:54 UTC-5, Jerzy Szczepkowski wrote:
You can get it from endpoints resource. The endpoint should have an annotation pointing to the leader.

$ kubectl get endpoints kube-controller-manager --namespace=kube-system  -o yaml

apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"kubernetes-master","leaseDurationSeconds":15,"acquireTime":"2017-02-14T14:05:57Z","renewTime":"2017-02-14T14:14:42Z","leaderTransitions":0}'
...


Regards,
Jerzy
On Tue, Feb 14, 2017 at 2:27 PM, Qian Zhang <zhq5...@gmail.com> wrote:
Hi,

I have a Kubernetes HA cluster which consists of 3 master nodes, each of them has kube-apiserver, kube-scheduler and kube-controller-manager running, and kube-scheduler and kube-controller-manager are started with the option "--leader-elect", my question is, is there a way to tell the current leader of kube-scheduler/kube-controller-manager? E.g., a Kubernetes API to get such info? Or directly get it from etcd?


Thanks,
Qian Zhang

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
To post to this group, send email to kubernet...@googlegroups.com.

Andy Xie

unread,
Dec 29, 2017, 5:55:07 AM12/29/17
to Kubernetes user discussion and Q&A
This should definitely be added to the doc.

在 2017年2月15日星期三 UTC+8下午4:51:35,Qian Zhang写道:
Thanks Jerzy!


Thanks,
Qian Zhang

On Tue, Feb 14, 2017 at 10:18 PM, 'Jerzy Szczepkowski' via Kubernetes user discussion and Q&A <kubernet...@googlegroups.com> wrote:
You can get it from endpoints resource. The endpoint should have an annotation pointing to the leader.

$ kubectl get endpoints kube-controller-manager --namespace=kube-system  -o yaml

apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    control-plane.alpha.kubernetes.io/leader: '{"holderIdentity":"kubernetes-master","leaseDurationSeconds":15,"acquireTime":"2017-02-14T14:05:57Z","renewTime":"2017-02-14T14:14:42Z","leaderTransitions":0}'
...


Regards,
Jerzy
On Tue, Feb 14, 2017 at 2:27 PM, Qian Zhang <zhq5...@gmail.com> wrote:
Hi,

I have a Kubernetes HA cluster which consists of 3 master nodes, each of them has kube-apiserver, kube-scheduler and kube-controller-manager running, and kube-scheduler and kube-controller-manager are started with the option "--leader-elect", my question is, is there a way to tell the current leader of kube-scheduler/kube-controller-manager? E.g., a Kubernetes API to get such info? Or directly get it from etcd?


Thanks,
Qian Zhang

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
To post to this group, send email to kubernet...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kubernetes-users/5Zf3WmXuOco/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kubernetes-use...@googlegroups.com.
To post to this group, send email to kubernet...@googlegroups.com.

Andy Xie

unread,
Dec 29, 2017, 11:45:59 AM12/29/17
to Kubernetes user discussion and Q&A
As the value for `control-plane.alpha.kubernetes.io/leader` is the output of json marshal. So, you can not just use the kubectl command line `kubectl -s http://APISERVER --namespace=kube-system get endpoints kube-controller-manager -o jsonpaata.annotations.control-plane\.alpha\.kubernetes\.io/leader}'` to extract. But be using `jq` you can do this `kubectl -s http://APISERVER --namespace=kube-system get endpoints kube-controller-manager -o jsonpath='{.metadata.annotations.control-plane\.alpha\.kubernetes\.io/leader}'|jq '.holderIdentity'`

在 2017年7月1日星期六 UTC+8上午3:24:20,Junaid Subhani写道:
Reply all
Reply to author
Forward
0 new messages