Overview/Background
Certain Kubernetes components, namely the kube-scheduler
and kube-controller-manager
, have the concept of a leader. When troubleshooting these components, it can be useful to know which instance is the leader, as only the current leader will log associated actions and events.
Solution
After a leader election has taken place and a leader has been determined for the kube-scheduler
and/or kube-controller-manager
, the leader (holderIdentity) is saved in its respective endpoint
. As such, we can use kubectl
to find the current leader.
kube-scheduler
To find the kube-scheduler
leader using kubectl
:
kubectl -n kube-system get endpoints kube-scheduler -o jsonpath='{.metadata.annotations.control-plane\.alpha\.kubernetes\.io/leader}'
kube-controller-manager
To find the kube-controller-manager
leader using kubectl
:
kubectl -n kube-system get endpoints kube-controller-manager -o jsonpath='{.metadata.annotations.control-plane\.alpha\.kubernetes\.io/leader}'