ETCD 命令
存储:
curl http://127.0.0.1:4001/v2/keys/testkey -XPUT -d value='testvalue'
curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd' -d ttl=5
获取:
curl http://127.0.0.1:4001/v2/keys/testkey
查看版本:
curl http://127.0.0.1:4001/version
删除:
curl -s http://127.0.0.1:4001/v2/keys/testkey -XDELETE
监视:
窗口1:curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd 1'
curl -s http://127.0.0.1:4001/v2/keys/message2?wait=true
窗口2:
curl -s http://127.0.0.1:4001/v2/keys/message2 -XPUT -d value='hello etcd 2'
自动创建key:
curl -s http://127.0.0.1:4001/v2/keys/message3 -XPOST -d value='hello etcd 1'
curl -s 'http://127.0.0.1:4001/v2/keys/message3?recursive=true&sorted=true'
创建目录:
curl -s http://127.0.0.1:4001/v2/keys/message8 -XPUT -d dir=true
删除目录:
curl -s 'http://127.0.0.1:4001/v2/keys/message7?dir=true' -XDELETE
curl -s 'http://127.0.0.1:4001/v2/keys/message7?recursive=true' -XDELETE
查看所有key:
curl -s http://127.0.0.1:4001/v2/keys/?recursive=true
存储数据:
curl -s http://127.0.0.1:4001/v2/keys/file -XPUT --data-urlencode value@upfile
使用etcdctl客户端:
存储:
etcdctl set /liuyiling/testkey "610" --ttl '100'
--swap-with-value value
获取:
etcdctl get /liuyiling/testkey
更新:
etcdctl update /liuyiling/testkey "world" --ttl '100'
删除:
etcdctl rm /liuyiling/testkey
使用ca获取:
etcdctl --cert-file=/etc/etcd/ssl/etcd.pem --key-file=/etc/etcd/ssl/etcd-key.pem --ca-file=/etc/etcd/ssl/ca.pem get /message
目录管理:
etcdctl mk /liuyiling/testkey "hello" 类似set,但是如果key已经存在,报错
etcdctl mkdir /liuyiling
etcdctl setdir /liuyiling
etcdctl updatedir /liuyiling
etcdctl rmdir /liuyiling
查看:
etcdctl ls --recursive
监视:
etcdctl watch mykey --forever + etcdctl update mykey "hehe"
#监视目录下所有节点的改变
etcdctl exec-watch --recursive /foo -- sh -c "echo hi"
etcdctl exec-watch mykey -- sh -c 'ls -al' + etcdctl update mykey "hehe"
etcdctl member list
集群启动步骤
1.启动一个etcd,任意机器,如192.168.1.1:2379
2.curl -X PUT http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222/_config/size -d value=3
3.etcd -name machine1 -initial-advertise-peer-urls http://127.0.0.1:2380 -listen-peer-urls http://127.0.0.1:2380 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222
4.如果是在三台不同的服务器上,则重复上面的命令3次,否则重复上面的命令1次+下面的命令2次
etcd -name machine2 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222 -addr 127.0.0.1:2389 -bind-addr 127.0.0.1:2389 -peer-addr 127.0.0.1:2390 -peer-bind-addr 127.0.0.1:2390
etcd -name machine3 -discovery http://192.168.1.1:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0f222 -addr 127.0.0.1:2409 -bind-addr 127.0.0.1:2409 -peer-addr 127.0.0.1:2490 -peer-bind-addr 127.0.0.1:2490
5.curl -L http://localhost:2379/v2/members | python -m json.tool
kubernetes etcd 命令
使用环境变量定义api版本
export ETCDCTL_API=3
etcd有目录结构类似linux文件系统,获取所有key看一看:
etcdctl get / –prefix –keys-only
把想删除的删掉,列如:
etcdctl del /registry/deployments/default/elevated-dragonfly-spinn-front50
删除deployments,pods这可以了,稍微减少一些资源,让kube-apiserver可以正常工作即可,其它资源还可以使用kubectl工具删除,删掉些资源后退出etcd把kube-apiserver的编排文件放回/etc/kubernetes/manifests目录,服务会再次启动,然后再清理重新部署。