etcdctl commonly used instructions (v3 version)

Introduction

Etcd is divided into etcd2 and etcd3 versions. The APIs between the two versions are not compatible with each other. Now most companies are using etcd3 version. This article also uses etcd3 as the demonstration object.

etcdctl tool The command line tool attached to etcd can easily manage the data in etcd.

There are two versions of etcdctl: v2 and v3. You can use the following methods to set the versions respectively:


#Set v2 version export ETCDCTL_API=2 #Set 
v3 version 
export ETCDCTL_API=3

Here we only introduce the etcdctl v3 version.

Configure v3 version

sudo vi ~ / .bashrc

#Set etcdctl as the v3 version 
export ETCDCTL_API=3 

#Set the endpoint information of etcd, that is, the ip:port of the etcd cluster, separated by commas 
export ENDPOINTS=10.10.10.45:2379,10.10.10.46:2379,10.10.10.47:2379

Common commands

1) View version

View version of the command

Enter: etcdctl version

2) Get the list of etcd members

Enter: etcdctl member list

The output information format includes fields, json, protobuf, simple, table, which are specified by --write-out, here I will try the table format

输入:etcdctl member list --write-out="table"

3) Write kv to etcd

etcdctl put key value

例如:etcdctl --endpoints=$ENDPOINTS put web3 'hello world3'

4) Query data from etcd

#Exactly query data with a key of web3 
etcdctl get web3 #Fuzzy  

query matches data with a prefix of web 
etcdctl get --prefix web #Fuzzy 

query matches a key with a prefix of web (no value is returned) 
./etcdctl --prefix --keys-only=true get web

5) Delete a key

key etcdctl

For example: etcdctl del web1

After the command is executed, the number of keys actually deleted is printed.

6) Lease agreement (ttl, expiration time)

a) View the list of leases

Execution: etcdctl lease list

b) Create a lease for a certain period of time, the unit is s: etcdctl lease grant n

Implementation: etcdctl lease grant 4000

c) Grant a lease (that is, expiration time) for a certain KV: etcdctl put --lease=name key value

执行:etcdctl  put web3 'hello world' --lease=1255775c01ff5f28

d) View lease information

Execution: etcdctl lease timetolive  1255775c01ff5f28

e) Reset the lease (equivalent to reset the remaining expiration time, the remaining expiration time of all keys bound to the lease becomes 4000s)

执行:etcdctl lease keep-alive 1255775c01ff5f28

f) Revocation of the lease (the KV granted the lease will be deleted at the same time as the lease is revoked)

Execution: etcdctl lease revoke 1255775c01ff5f28

 The above is the simple and practical of etcdctl. If you have any questions, you can leave a message at the back~

Blogger: test to make money (a test open code farmer who is not 996 but 996)

Motto: Focus on test development and automated operation and maintenance, work hard to read, think and write, and lay the financial freedom for the life of the internal volume.

Content categories: technology improvement, workplace miscellaneous talk, career development, reading and writing, investment and financial management, healthy life.

csdn:https://blog.csdn.net/ccgshigao

Blog Park: https://www.cnblogs.com/qa-freeroad/

51cto :https://blog.51cto.com/14900374

WeChat public account : test to make money (share exclusive content and resources regularly)



Guess you like

Origin blog.51cto.com/14900374/2642151