View etcd data through the command line

etcd2 and etcd3 are incompatible, and their api parameters are also different. Please see etcdctl -h for details.

api2 使用方法

ETCDCTL_API=2 etcdctl ls /

api3 使用方法
Starting with kubernetes 1.6, etcd clusters use version 3

export ETCDCTL_API=3
1. Check version
etcdctl version
2. View etcd data
etcdctl get "" --from-key 

etcdctl get '' --prefix

Only list etcd key information

etcdctl get "" --from-key --keys-only
3. View the lease list
etcdctl lease list
输出:
[root@jlzc-backup-209-55 ~]# etcdctl lease list
found 4 leases
694d892f19208fd9
694d892f19208fd6
694d892f19208fe5
694d892f19208fe0
etcdctl lease timetolive 【ID】
输出:
[root@jlzc-backup-209-55 ~]# etcdctl lease timetolive 694d892f19208fd9
lease 694d892f19208fd9 granted with TTL(10s), remaining(9s)

Detailed explanation of parameters:

1. put
put #将给定的key写入到存储
--ignore-lease[=false] #使用当前租约更新key
--ignore-value[=false] #使用当前值更新key
--lease="0" # 要附加到key的租约ID(十六进制)
--prev-kv[=false] # 返回修改前的上一个键值对

2. get
get #获取给定key或给定范围的key
--consistency="l" # 'l' 代表线性读(执行raft), 's' 代表串行化读
--count-only[=false] # 仅获取计数
--from-key[=false] #使用byte值比较获取大于或等于给定键的键,类似*key*,但不等于
--keys-only[=false] # 仅获取key
--limit=0 #最大结果数
--order="" #结果排序,ASCEND 或 DESCEND (默认 ASCEND)
--prefix[=false] # 获取具有匹配前缀的key,key*
--print-value-only[=false] #用“simple”输出格式时仅打印值
--rev=0 #指定kv版本
--sort-by="" # 指定排序字段,CREATE, KEY, MODIFY, VALUE, or VERSION

3. del
del #删除指定的键或键范围
--from-key[=false] # 删除大于等于给定key的所有key(按byte值比较)
--prefix[=false] # 按前缀匹配删除
--prev-kv[=false] # 删除后是否返回被删除的键值对
4. lease(租约)
lease grant # 创建租约
lease keep-alive # 开启线程,自动续约
--once[=false] # 仅续约一次
lease list #列出所有活动的租约
lease revoke #撤销租约
lease timetolive # 获取租约信息
--keys[=false] #获取附加到此租约的key

watch(事件监听)
watch #监听键值或前缀的事件流
-i, --interactive[=false] # 交互式模式
--prefix[=false] # 监听前缀
--prev-kv[=false] # 获取事件发生前的上一个键值对
--progress-notify[=false] # 从服务器获取定期监视进度通知
--rev=0 # 从指定版本开始监听

Guess you like

Origin blog.csdn.net/ichen820/article/details/133273614
Recommended