1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| 清理当前版本之前的数据(这是清理etcd集群) # 查看存储统计信息 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.37:2379,https://192.168.64.38:2379 \ endpoint status -w table
# 获取当前版本信息 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.37:2379,https://192.168.64.38:2379 \ endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9].*' # 返回:302908777
# 当前版本之前的版本全部压缩 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.37:2379,https://192.168.64.38:2379 \ compact 302908777
# 将上一步中压缩的数据全部清理,只保留当前版本最新key值 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.37:2379,https://192.168.64.38:2379 \ defrag --cluster
------以下是其它一些操作 # 按前缀删除 docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.35:2379,https://192.168.64.37:2379 \ del /tmp/ --prefix
# 分页列出key # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.35:2379,https://192.168.64.37:2379 \ get --prefix "" | less
# 列出所有键值对并获取它们的创建时间 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.35:2379,https://192.168.64.37:2379 \ get "" --prefix --keys-only
# 获取键的详细信息 # docker run --rm -it --net host -v /etc/kubernetes:/etc/kubernetes \ registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.7-0 etcdctl --cert \ /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key --cacert \ /etc/kubernetes/pki/etcd/ca.crt \ --endpoints=https://192.168.64.35:2379,https://192.168.64.35:2379,https://192.168.64.37:2379 \ get "" --prefix --write-out=fields
|