Skip to content

Commit 3fbb55b

Browse files
author
Tim Bannister
authored
Improve Lease concept (#38307)
* Improve Lease concept * Write “heartbeat” consistently (within Lease concept page).
1 parent 4af76d6 commit 3fbb55b

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

content/en/docs/concepts/architecture/leases.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ weight: 30
66

77
<!-- overview -->
88

9-
Distributed systems often have a need for "leases", which provides a mechanism to lock shared resources and coordinate activity between nodes.
10-
In Kubernetes, the "lease" concept is represented by `Lease` objects in the `coordination.k8s.io` API group, which are used for system-critical
11-
capabilities like node heart beats and component-level leader election.
9+
Distributed systems often have a need for _leases_, which provide a mechanism to lock shared resources
10+
and coordinate activity between members of a set.
11+
In Kubernetes, the lease concept is represented by [Lease](/docs/reference/kubernetes-api/cluster-resources/lease-v1/)
12+
objects in the `coordination.k8s.io` {{< glossary_tooltip text="API Group" term_id="api-group" >}},
13+
which are used for system-critical capabilities such as node heartbeats and component-level leader election.
1214

1315
<!-- body -->
1416

15-
## Node Heart Beats
17+
## Node heartbeats {#node-heart-beats}
1618

17-
Kubernetes uses the Lease API to communicate kubelet node heart beats to the Kubernetes API server.
19+
Kubernetes uses the Lease API to communicate kubelet node heartbeats to the Kubernetes API server.
1820
For every `Node` , there is a `Lease` object with a matching name in the `kube-node-lease`
19-
namespace. Under the hood, every kubelet heart beat is an UPDATE request to this `Lease` object, updating
21+
namespace. Under the hood, every kubelet heartbeat is an **update** request to this `Lease` object, updating
2022
the `spec.renewTime` field for the Lease. The Kubernetes control plane uses the time stamp of this field
2123
to determine the availability of this `Node`.
2224

2325
See [Node Lease objects](/docs/concepts/architecture/nodes/#heartbeats) for more details.
2426

25-
## Leader Election
27+
## Leader election
2628

27-
Leases are also used in Kubernetes to ensure only one instance of a component is running at any given time.
29+
Kubernetes also uses Leases to ensure only one instance of a component is running at any given time.
2830
This is used by control plane components like `kube-controller-manager` and `kube-scheduler` in
2931
HA configurations, where only one instance of the component should be actively running while the other
3032
instances are on stand-by.
3133

32-
## API Server Identity
34+
## API server identity
3335

3436
{{< feature-state for_k8s_version="v1.26" state="beta" >}}
3537

@@ -43,22 +45,23 @@ You can inspect Leases owned by each kube-apiserver by checking for lease object
4345
with the name `kube-apiserver-<sha256-hash>`. Alternatively you can use the label selector `k8s.io/component=kube-apiserver`:
4446

4547
```shell
46-
$ kubectl -n kube-system get lease -l k8s.io/component=kube-apiserver
48+
kubectl -n kube-system get lease -l k8s.io/component=kube-apiserver
49+
```
50+
```
4751
NAME HOLDER AGE
4852
kube-apiserver-c4vwjftbvpc5os2vvzle4qg27a kube-apiserver-c4vwjftbvpc5os2vvzle4qg27a_9cbf54e5-1136-44bd-8f9a-1dcd15c346b4 5m33s
4953
kube-apiserver-dz2dqprdpsgnm756t5rnov7yka kube-apiserver-dz2dqprdpsgnm756t5rnov7yka_84f2a85d-37c1-4b14-b6b9-603e62e4896f 4m23s
5054
kube-apiserver-fyloo45sdenffw2ugwaz3likua kube-apiserver-fyloo45sdenffw2ugwaz3likua_c5ffa286-8a9a-45d4-91e7-61118ed58d2e 4m43s
5155
```
5256

53-
The SHA256 hash used in the lease name is based on the OS hostname as seen by kube-apiserver. Each kube-apiserver should be
57+
The SHA256 hash used in the lease name is based on the OS hostname as seen by that API server. Each kube-apiserver should be
5458
configured to use a hostname that is unique within the cluster. New instances of kube-apiserver that use the same hostname
55-
will take over existing Leases using a new holder identity, as opposed to instantiating new lease objects. You can check the
59+
will take over existing Leases using a new holder identity, as opposed to instantiating new Lease objects. You can check the
5660
hostname used by kube-apisever by checking the value of the `kubernetes.io/hostname` label:
5761

5862
```shell
59-
$ kubectl -n kube-system get lease kube-apiserver-c4vwjftbvpc5os2vvzle4qg27a -o yaml
63+
kubectl -n kube-system get lease kube-apiserver-c4vwjftbvpc5os2vvzle4qg27a -o yaml
6064
```
61-
6265
```yaml
6366
apiVersion: coordination.k8s.io/v1
6467
kind: Lease
@@ -78,3 +81,23 @@ spec:
7881
```
7982
8083
Expired leases from kube-apiservers that no longer exist are garbage collected by new kube-apiservers after 1 hour.
84+
85+
You can disable API server identity leases by disabling the `APIServerIdentity`
86+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/).
87+
88+
## Workloads {#custom-workload}
89+
90+
Your own workload can define its own use of Leases. For example, you might run a custom
91+
{{< glossary_tooltip term_id="controller" text="controller" >}} where a primary or leader member
92+
performs operations that its peers do not. You define a Lease so that the controller replicas can select
93+
or elect a leader, using the Kubernetes API for coordination.
94+
If you do use a Lease, it's a good practice to define a name for the Lease that is obviously linked to
95+
the product or component. For example, if you have a component named Example Foo, use a Lease named
96+
`example-foo`.
97+
98+
If a cluster operator or another end user could deploy multiple instances of a component, select a name
99+
prefix and pick a mechanism (such as hash of the name of the Deployment) to avoid name collisions
100+
for the Leases.
101+
102+
You can use another approach so long as it achieves the same outcome: different software products do
103+
not conflict with one another.

content/en/docs/concepts/architecture/nodes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ availability of each node, and to take action when failures are detected.
274274
For nodes there are two forms of heartbeats:
275275

276276
* updates to the `.status` of a Node
277-
* [Lease](/docs/reference/kubernetes-api/cluster-resources/lease-v1/) objects
277+
* [Lease](/docs/concepts/architecture/leases/) objects
278278
within the `kube-node-lease`
279279
{{< glossary_tooltip term_id="namespace" text="namespace">}}.
280280
Each Node has an associated Lease object.

content/en/docs/concepts/overview/working-with-objects/namespaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Kubernetes starts with four initial namespaces:
4444
: Kubernetes includes this namespace so that you can start using your new cluster without first creating a namespace.
4545

4646
`kube-node-lease`
47-
: This namespace holds [Lease](/docs/reference/kubernetes-api/cluster-resources/lease-v1/) objects associated with each node. Node leases allow the kubelet to send [heartbeats](/docs/concepts/architecture/nodes/#heartbeats) so that the control plane can detect node failure.
47+
: This namespace holds [Lease](/docs/concepts/architecture/leases/) objects associated with each node. Node leases allow the kubelet to send [heartbeats](/docs/concepts/architecture/nodes/#heartbeats) so that the control plane can detect node failure.
4848

4949
`kube-public`
5050
: This namespace is readable by *all* clients (including those not authenticated). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement.

content/en/docs/reference/command-line-tools-reference/feature-gates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Each feature gate is designed for enabling/disabling a specific feature:
383383
to see the requesting subject's authentication information.
384384
See [API access to authentication information for a client](/docs/reference/access-authn-authz/authentication/#self-subject-review)
385385
for more details.
386-
- `APIServerIdentity`: Assign each API server an ID in a cluster.
386+
- `APIServerIdentity`: Assign each API server an ID in a cluster, using a [Lease](/docs/concepts/architecture/leases).
387387
- `APIServerTracing`: Add support for distributed tracing in the API server.
388388
See [Traces for Kubernetes System Components](/docs/concepts/cluster-administration/system-traces) for more details.
389389
- `AdvancedAuditing`: Enable [advanced auditing](/docs/tasks/debug/debug-cluster/audit/#advanced-audit)

0 commit comments

Comments
 (0)