From 944e04f889b7e54a8fe7f4dd20814efb569282bb Mon Sep 17 00:00:00 2001 From: ashrafahmed9 Date: Wed, 3 Jun 2026 13:27:24 +0530 Subject: [PATCH] docs: revise lease tutorial with prerequisites and sections Signed-off-by: ashrafahmed9 --- .../v3.5/tutorials/how-to-create-lease.md | 48 ++++++++++++++++--- .../tasks/developer/how-to-create-lease.md | 48 ++++++++++++++++--- .../tasks/developer/how-to-create-lease.md | 48 ++++++++++++++++--- 3 files changed, 123 insertions(+), 21 deletions(-) diff --git a/content/en/docs/v3.5/tutorials/how-to-create-lease.md b/content/en/docs/v3.5/tutorials/how-to-create-lease.md index 2b86576bb..51cbe40b5 100644 --- a/content/en/docs/v3.5/tutorials/how-to-create-lease.md +++ b/content/en/docs/v3.5/tutorials/how-to-create-lease.md @@ -1,23 +1,57 @@ --- -title: How to create lease -description: Guide to creating a lease in etcd +title: Granting and revoking leases +description: Guide to granting and revoking leases in etcd weight: 700 --- -`lease` to write with TTL: +## Prerequisites +- A running etcd cluster (see [getting started](/docs/v3.5/quickstart/)) +- `etcdctl` installed and configured -![07_etcdctl_lease_2016050501](https://storage.googleapis.com/etcd/demo/07_etcdctl_lease_2016050501.gif) +The following variables are used in this guide: -```shell +- `$ENDPOINTS` — the etcd endpoint(s), e.g. `localhost:2379` +- `lease grant` — creates a new lease with a TTL (time-to-live) in seconds +- `put --lease` — attaches a key to a lease so it expires with it +- `lease keep-alive` — refreshes a lease to prevent it from expiring +- `lease revoke` — immediately expires a lease and deletes its keys + +For more information on leases, see [Interacting with etcd: Grant leases](/docs/v3.5/dev-guide/interacting_v3/#grant-leases). + +## Grant a lease + +Grant a lease with a TTL of 300 seconds: + +```bash etcdctl --endpoints=$ENDPOINTS lease grant 300 # lease 2be7547fbc6a5afa granted with TTL(300s) +``` + +Attach a key to the lease so it is automatically deleted when the lease expires: +```bash etcdctl --endpoints=$ENDPOINTS put sample value --lease=2be7547fbc6a5afa etcdctl --endpoints=$ENDPOINTS get sample +``` + +Keep the lease alive by refreshing it before it expires: +```bash etcdctl --endpoints=$ENDPOINTS lease keep-alive 2be7547fbc6a5afa +``` + +## Revoke a lease + +Revoke the lease immediately, which also deletes all keys attached to it: + +```bash etcdctl --endpoints=$ENDPOINTS lease revoke 2be7547fbc6a5afa -# or after 300 seconds -etcdctl --endpoints=$ENDPOINTS get sample ``` + +After revocation (or after the TTL expires), the key is no longer accessible: + +```bash +etcdctl --endpoints=$ENDPOINTS get sample +# (empty response) +``` \ No newline at end of file diff --git a/content/en/docs/v3.6/tasks/developer/how-to-create-lease.md b/content/en/docs/v3.6/tasks/developer/how-to-create-lease.md index 2b86576bb..51cbe40b5 100644 --- a/content/en/docs/v3.6/tasks/developer/how-to-create-lease.md +++ b/content/en/docs/v3.6/tasks/developer/how-to-create-lease.md @@ -1,23 +1,57 @@ --- -title: How to create lease -description: Guide to creating a lease in etcd +title: Granting and revoking leases +description: Guide to granting and revoking leases in etcd weight: 700 --- -`lease` to write with TTL: +## Prerequisites +- A running etcd cluster (see [getting started](/docs/v3.5/quickstart/)) +- `etcdctl` installed and configured -![07_etcdctl_lease_2016050501](https://storage.googleapis.com/etcd/demo/07_etcdctl_lease_2016050501.gif) +The following variables are used in this guide: -```shell +- `$ENDPOINTS` — the etcd endpoint(s), e.g. `localhost:2379` +- `lease grant` — creates a new lease with a TTL (time-to-live) in seconds +- `put --lease` — attaches a key to a lease so it expires with it +- `lease keep-alive` — refreshes a lease to prevent it from expiring +- `lease revoke` — immediately expires a lease and deletes its keys + +For more information on leases, see [Interacting with etcd: Grant leases](/docs/v3.5/dev-guide/interacting_v3/#grant-leases). + +## Grant a lease + +Grant a lease with a TTL of 300 seconds: + +```bash etcdctl --endpoints=$ENDPOINTS lease grant 300 # lease 2be7547fbc6a5afa granted with TTL(300s) +``` + +Attach a key to the lease so it is automatically deleted when the lease expires: +```bash etcdctl --endpoints=$ENDPOINTS put sample value --lease=2be7547fbc6a5afa etcdctl --endpoints=$ENDPOINTS get sample +``` + +Keep the lease alive by refreshing it before it expires: +```bash etcdctl --endpoints=$ENDPOINTS lease keep-alive 2be7547fbc6a5afa +``` + +## Revoke a lease + +Revoke the lease immediately, which also deletes all keys attached to it: + +```bash etcdctl --endpoints=$ENDPOINTS lease revoke 2be7547fbc6a5afa -# or after 300 seconds -etcdctl --endpoints=$ENDPOINTS get sample ``` + +After revocation (or after the TTL expires), the key is no longer accessible: + +```bash +etcdctl --endpoints=$ENDPOINTS get sample +# (empty response) +``` \ No newline at end of file diff --git a/content/en/docs/v3.7/tasks/developer/how-to-create-lease.md b/content/en/docs/v3.7/tasks/developer/how-to-create-lease.md index 2b86576bb..51cbe40b5 100644 --- a/content/en/docs/v3.7/tasks/developer/how-to-create-lease.md +++ b/content/en/docs/v3.7/tasks/developer/how-to-create-lease.md @@ -1,23 +1,57 @@ --- -title: How to create lease -description: Guide to creating a lease in etcd +title: Granting and revoking leases +description: Guide to granting and revoking leases in etcd weight: 700 --- -`lease` to write with TTL: +## Prerequisites +- A running etcd cluster (see [getting started](/docs/v3.5/quickstart/)) +- `etcdctl` installed and configured -![07_etcdctl_lease_2016050501](https://storage.googleapis.com/etcd/demo/07_etcdctl_lease_2016050501.gif) +The following variables are used in this guide: -```shell +- `$ENDPOINTS` — the etcd endpoint(s), e.g. `localhost:2379` +- `lease grant` — creates a new lease with a TTL (time-to-live) in seconds +- `put --lease` — attaches a key to a lease so it expires with it +- `lease keep-alive` — refreshes a lease to prevent it from expiring +- `lease revoke` — immediately expires a lease and deletes its keys + +For more information on leases, see [Interacting with etcd: Grant leases](/docs/v3.5/dev-guide/interacting_v3/#grant-leases). + +## Grant a lease + +Grant a lease with a TTL of 300 seconds: + +```bash etcdctl --endpoints=$ENDPOINTS lease grant 300 # lease 2be7547fbc6a5afa granted with TTL(300s) +``` + +Attach a key to the lease so it is automatically deleted when the lease expires: +```bash etcdctl --endpoints=$ENDPOINTS put sample value --lease=2be7547fbc6a5afa etcdctl --endpoints=$ENDPOINTS get sample +``` + +Keep the lease alive by refreshing it before it expires: +```bash etcdctl --endpoints=$ENDPOINTS lease keep-alive 2be7547fbc6a5afa +``` + +## Revoke a lease + +Revoke the lease immediately, which also deletes all keys attached to it: + +```bash etcdctl --endpoints=$ENDPOINTS lease revoke 2be7547fbc6a5afa -# or after 300 seconds -etcdctl --endpoints=$ENDPOINTS get sample ``` + +After revocation (or after the TTL expires), the key is no longer accessible: + +```bash +etcdctl --endpoints=$ENDPOINTS get sample +# (empty response) +``` \ No newline at end of file