client-go/examples/leader-election
Davanum Srinivas 75fea27a27 switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
..
main.go switch over k/k to use klog v2 2020-04-17 15:25:06 -04:00
README.md chore(*): update election example (#82821) 2019-10-14 07:06:53 +00:00

Leader Election Example

This example demonstrates how to use the leader election package.

Running

Run the following three commands in separate terminals. Each terminal needs a unique id.

# first terminal
go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=1

# second terminal
go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=2

# third terminal
go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=3

You can ignore the -kubeconfig flag if you are running these commands in the Kubernetes cluster.

Now kill the existing leader. You will see from the terminal outputs that one of the remaining two processes will be elected as the new leader.