Skip to content
Branch: master
Find file History
bbbmj and k8s-publishing-bot chore(*): update election example (#82821)
* feat(*): simplify leader election example

* chore(*): fix with comment

* chore(*): add os.exit

* chore(*): fix typo

Kubernetes-commit: 1185012da65edf802f22aff24141c0466a2a3ac8
Latest commit c51c673 Oct 11, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md chore(*): update election example (#82821) Oct 14, 2019
main.go chore(*): update election example (#82821) Oct 14, 2019

README.md

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.

You can’t perform that action at this time.