ETCD的常用命令
Note that any key that was created using the v2 API will not be able to be queried via the v3 API. A v3 API etcdctl get
of a v2 key will exit with 0 and no key data, this is the expected behaviour.
export ETCDCTL_API=3
etcdctl version
1、etcdctl put foo bar
2、etcdctl put foo1 bar1 --lease=1234abcd(创建的租约ID)
3、etcdctl get foo
4、etcdctl get foo --hex
5、$ etcdctl get --prefix foo
foo bar
foo1 bar1
foo2 bar2
foo3 bar3
6、etcdctl get --prefix --limit=2 foo
7、版本,每次修订KEY,都会全局版本加一
Suppose an etcd cluster already has the following keys:
foo = bar # revision = 2
foo1 = bar1 # revision = 3
foo = bar_new # revision = 4
foo1 = bar1_new # revision = 5
Here are an example to access the past versions of keys:
$ etcdctl get --prefix foo # access the most recent versions of keys
foo
bar_new
foo1
bar1_new
$ etcdctl get --prefix --rev=4 foo # access the versions of keys at revision 4
foo
bar_new
foo1
bar1
$ etcdctl get --prefix --rev=3 foo # access the versions of keys at revision 3
foo
bar
foo1
bar1
$ etcdctl get --prefix --rev=2 foo # access the versions of keys at revision 2
foo
bar
$ etcdctl get --prefix --rev=1 foo # access the versions of keys at revision 1
8、读取》=KEY
Suppose an etcd cluster already has the following keys:
a = 123
b = 456
z = 789
Here is the command to read keys which are greater than or equal to the byte value of key b
:
$ etcdctl get --from-key b b 456 z 789
9、etcdctl del foo1 foo9--范围删除
10、$ etcdctl del --prev-kv zoo
Here is the command to delete key zoo
with the deleted key value pair returned
1 # one key is deleted
zoo # deleted key
val # the value of the deleted key
11、$ etcdctl del --from-key b
Here is the command to delete keys which are greater than or equal to the byte value of key b
:
2 # two keys are deleted