# Use on ANY node
export ETCDCTL_API=3
export ETCD_ENDPOINTS="http://192.168.8.242:2379,http://192.168.8.194:2379,http://192.168.8.103:2379"
alias etcd3='etcdctl --endpoints="$ETCD_ENDPOINTS"'

1) Store & Read Keys (CRUD)

# Create/Update
etcd3 put /app/config/region "ca-central-1"
etcd3 put /app/config/db "postgres://user:pass@host/db"

# Read single
etcd3 get /app/config/region

# Read by prefix
etcd3 get /app/config/ --prefix

# Read values only (nice for scripts)
etcd3 get /app/config/region --print-value-only

# Delete one / delete subtree
etcd3 del /app/config/region
etcd3 del /app/config/ --prefix

2) Watch for Changes (live streaming)

# Terminal A (any node): watch a key or a whole prefix
etcd3 watch /app/config/ --prefix

# Terminal B: mutate something and see it stream to A
etcd3 put /app/config/featureX "enabled"

3) Ephemeral Keys with TTL (Leases)

# Create a 60s lease and keep it alive
lease=$(etcd3 lease grant 60 | awk '/lease/{print $3}')
etcd3 lease keep-alive "$lease" &   # keep-alive in background

# Attach key to lease (auto-expires)
etcd3 put --lease="$lease" /services/web/192.168.8.50 '{"port":8080,"zone":"A"}'

# List live instances
etcd3 get /services/web/ --prefix