|
| 1 | +--- |
| 2 | +reviewers: |
| 3 | +- jpbetz |
| 4 | +title: Coordinated Leader Election |
| 5 | +content_type: concept |
| 6 | +weight: 200 |
| 7 | +--- |
| 8 | + |
| 9 | +<!-- overview --> |
| 10 | + |
| 11 | +{{< feature-state feature_gate_name="CoordinatedLeaderElection" >}} |
| 12 | + |
| 13 | +Kubernetes {{< skew currentVersion >}} includes an alpha feature that allows |
| 14 | +components to deterministically select a leader via Coordinated Leader Election. |
| 15 | +This is useful to satisfy Kubernetes version skew during cluster upgrades. |
| 16 | +Currently, the only supported selection strategy is `OldestEmulationVersion`, |
| 17 | +preferring the leader with the lowest emulation version, followed by binary |
| 18 | +version, followed by creation timestamp. |
| 19 | + |
| 20 | +## Enabling Coordinated Leader Election |
| 21 | + |
| 22 | +Ensure that `CoordinatedLeaderElection` [feature |
| 23 | +gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled |
| 24 | +when you start the {{< glossary_tooltip text="API Server" |
| 25 | +term_id="kube-apiserver" >}}: and that the `coordination.k8s.io/v1alpha1` API is |
| 26 | +enabled. |
| 27 | + |
| 28 | +This can be done by setting `FEATURE_GATES="CoordinatedLeaderElection=true"` and |
| 29 | +`RUNTIME_CONFIG="coordination.k8s.io/v1alpha1=true"`. |
| 30 | + |
| 31 | +## Component Configuration |
| 32 | + |
| 33 | +With Coordinated Leader Election, components need to both run a LeaseCandidate |
| 34 | +and Lease goroutine (both found in client-go/pkg/leaderelection). Two components |
| 35 | +(kube-controller-manager and kube-scheduler) will automatically use coordinated |
| 36 | +leader election if enabled. Please refer to the example found in |
| 37 | +`k8s.io/cmd/kube-scheduler/app/server.go` on set up. |
| 38 | + |
| 39 | +The created LeaseCandidate object looks similar to below: |
| 40 | + |
| 41 | +``` |
| 42 | +apiVersion: coordination.k8s.io/v1alpha1 |
| 43 | +kind: LeaseCandidate |
| 44 | +metadata: |
| 45 | + name: hostname_uuid |
| 46 | + namespace: kube-system |
| 47 | +spec: |
| 48 | + binaryVersion: 1.31.0 |
| 49 | + emulationVersion: 1.31.0 |
| 50 | + leaseName: kube-scheduler |
| 51 | + preferredStrategies: |
| 52 | + - OldestEmulationVersion |
| 53 | + renewTime: "2024-07-30T03:45:18.325483Z" |
| 54 | +``` |
| 55 | + |
| 56 | +Please refer to the documentation for LeaseCandidate for the full API details. |
0 commit comments