目的
由于 etcd DB 大
需要对 db 执行 defrag 操作
BUG
db 更大了
解决方法
升级 etcd 至 3.14 以后版本
现象
查询集群状态
[apps@GD9-xxx-002 ~]$ /apps/svr/etcd/bin/etcdctl cluster-health
member 1abxxxx77d2 is healthy: got healthy result from http://10.200.121.88:2379
member 30xxxxx59da is healthy: got healthy result from http://10.200.121.92:2379
member 37xxx522194 is healthy: got healthy result from http://10.200.121.90:2379
member 3exxxx3c5cb is healthy: got healthy result from http://10.200.121.91:2379
member dfxxxe3e85b is healthy: got healthy result from http://10.200.121.89:2379
cluster is healthy
开始时的磁盘空间大小 1.1GB
[apps@GD9-xxx-001 ~]$ ETCDCTL_API=3 /apps/svr/etcd/bin/etcdctl endpoint status -w table
+----------------+------------------+---------+---------+-----------+-----------+--------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+----------------+------------------+---------+---------+-----------+-----------+--------------+
| 127.0.0.1:2379 | 1axxxxxxxxxe77d2 | 3.0.6 | 1.1 GB | false | 993 | 137305385788 |
+----------------+------------------+---------+---------+-----------+-----------+--------------+
备份
[apps@GD9-xxxx-001 ~]$ ETCDCTL_API=3 /apps/svr/etcd/bin/etcdctl snapshot save /home/apps/backup/$(date +%F)/k8s_etcd_$(hostname)_$(date +%F-%H-%M).db
Snapshot saved at /home/apps/backup/2021-01-21/k8s_etcd_GD9-xxxx-001_2021-01-21-15-41.db
$ ls /home/apps/backup/2021-01-21/k8s_etcd_GD9-xxxx-001_2021-01-21-15-41.db -lh
-rw-rw-r-- 1 apps apps 1.1G Jan 21 15:42 /home/apps/backup/2021-01-21/k8s_etcd_GD9-xxxxx-001_2021-01-21-15-41.db
```
执行 defrag
```
ETCDCTL_API=3 /apps/svr/etcd/bin/etcdctl --command-timeout=60000s defrag
结束后 DB 变大了
[apps@GD9-xxx-001 etcd-3.0.6]$ ETCDCTL_API=3 /apps/svr/etcd/bin/etcdctl endpoint status -w table
+----------------+------------------+---------+---------+-----------+-----------+--------------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
+----------------+------------------+---------+---------+-----------+-----------+--------------+
| 127.0.0.1:2379 | 1axxxxxxxxxx77d2 | 3.0.6 | 2.0 GB | false | 993 | 137308566408 |
+----------------+------------------+---------+---------+-----------+-----------+--------------+
参考 GIT BUG REPORT
https://github.com/etcd-io/etcd/issues/7551