Tuesday, May 2, 2017

some basic etcd commands

1- enable etcd to listen on other interface, for example you have set your eth0 with ip 192.168.58.75, so the etcd configuration in /etc.default/etcd will be

ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://localhost:4001,http://192.168.58.75:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379,http://localhost:4001,http://192.168.58.75:2379"





2- restart etcd service to take effect with new configuration
$ sudo /etc/init.d/etcd restart

3- to interact with etcd, we can use curl or other http client, or can use etcdctl

- to get auth enable status, we can either command below

$ etcdctl  auth enable
or
$ curl http://127.0.0.1:2379/v2/auth/enable -XGET

4- add user root and enable authentication
$ etcdctl user add root
$ curl http://127.0.0.1:2379/v2/auth/enable -XPUT -d '{"enabled":"true"}' --user root:password


5- to get list of users
$ curl http://127.0.0.1:2379/v2/auth/users -XGET --user root:password
or
$ etcdctl --username root user list




6- create list delete keys


- create key name msg2 with value =hello
$ curl http://127.0.0.1:2379/v2/keys/msg2 -XPUT -d value="hello" --user root:password
{"action":"set","node":{"key":"/msg2","value":"hello","modifiedIndex":21,"createdIndex":21}} 
or
$ etcdctl --username root set /msg2 hello 

- list keys

$ etcdctl ls

- to deletes
$ etcdctl  rm /msg2
or
$ curl http://127.0.0.1:2379/v2/keys/msg2 -XDELETE

No comments:

Post a Comment