Version v3.7-DRAFT of the documentation is in DRAFT status. For the latest stable documentation, see v3.6.
Granting and revoking leases
Guide to granting and revoking leases in etcd
Prerequisites
- A running etcd cluster (see getting started)
etcdctlinstalled and configured
The following variables are used in this guide:
$ENDPOINTS— the etcd endpoint(s), e.g.localhost:2379lease grant— creates a new lease with a TTL (time-to-live) in secondsput --lease— attaches a key to a lease so it expires with itlease keep-alive— refreshes a lease to prevent it from expiringlease revoke— immediately expires a lease and deletes its keys
For more information on leases, see Interacting with etcd: Grant leases.
Grant a lease
Grant a lease with a TTL of 300 seconds:
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:
etcdctl --endpoints=$ENDPOINTS put sample value --lease=2be7547fbc6a5afa
etcdctl --endpoints=$ENDPOINTS get sample
Keep the lease alive by refreshing it before it expires:
etcdctl --endpoints=$ENDPOINTS lease keep-alive 2be7547fbc6a5afa
Revoke a lease
Revoke the lease immediately, which also deletes all keys attached to it:
etcdctl --endpoints=$ENDPOINTS lease revoke 2be7547fbc6a5afa
After revocation (or after the TTL expires), the key is no longer accessible:
etcdctl --endpoints=$ENDPOINTS get sample
# (empty response)
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.