...
1# Leader Election Example
2
3This example demonstrates how to use the leader election package.
4
5## Running
6
7Run the following three commands in separate terminals. Each terminal needs a unique `id`.
8
9```bash
10# first terminal
11go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=1
12
13# second terminal
14go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=2
15
16# third terminal
17go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=3
18```
19
20> You can ignore the `-kubeconfig` flag if you are running these commands in the Kubernetes cluster.
21
22Now 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.
View as plain text