| 1 |
# Leader Election Example |
| 2 |
|
| 3 |
This example demonstrates how to use the leader election package. |
| 4 |
|
| 5 |
## Running |
| 6 |
|
| 7 |
Run the following three commands in separate terminals. Each terminal needs a unique `id`. |
| 8 |
|
| 9 |
```bash |
| 10 |
# first terminal |
| 11 |
go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=1 |
| 12 |
|
| 13 |
# second terminal |
| 14 |
go run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=2 |
| 15 |
|
| 16 |
# third terminal |
| 17 |
go 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 |
|
| 22 |
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. |