How to know if a container is running on a leader kube-scheduler pod of a HA cluster?

8/8/2019

I have a HA cluster(say 3 masters with 1 kubes-scheduler pod on each master). There is a container running in each kube-scheduler pod. Inside this container, there two problems need to be solved here:

  1. How to know which kube-scheduler pod the container is running on?
  2. How to know if the kube-scheduler this container is running on is a leader?

I know the "holderIdentity" field of the "...kubernetes.io/leader" annotation of the pod will tell the ID of the leader. Then the only question is how to know which pod the container is running on. Or there is a way I can simply know if the pod I'm running is a leader.

-- JoyceLee
containers
kube-scheduler
kubernetes
kubernetes-pod
pod

1 Answer

8/8/2019

You can check the logs of kube-scheduler. You shall see lock is held by <HolderIdentity> and has not yet expired in the logs of non-leader Pods. And also successfully acquired lease or successfully renewed lease in the leader Pod logs.

-- wineinlib
Source: StackOverflow