@@ -30,19 +30,37 @@ Once inside the master we can execute the following commands:
3030sudo -i
3131# get etcd container id
3232ETCD=` crictl ps --label io.kubernetes.container.name=etcd --quiet`
33+ # check the size
34+ crictl exec $ETCD sh -c " etcdctl endpoint status --write-out=table"
35+ # at this point we should unset ETCDCTL_ENDPOINTS
3336# get the revision
34- crictl exec $ETCD etcdctl endpoint status --write-out fields | sed -nE ' s,"Revision" : ([0-9]+),\1,p'
37+ crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl endpoint status --write-out fields" | sed -nE ' s,"Revision" : ([0-9]+),\1,p'
3538# output:
3639# 6031370795
37- # 6031370796
38- # 6031370796
3940# compact the revision
40- crictl exec $ETCD etcdctl compact 6031370795
41+ crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl compact 6031370795"
4142# defrag
42- crictl exec $ETCD etcdctl defrag 6031370795 --command-timeout 120s
43+ crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl defrag 6031370795 --command-timeout 120s"
44+ # verify if the size decreased
45+ crictl exec $ETCD sh -c " etcdctl endpoint status --write-out=table"
4346```
4447
4548** Important:**
4649
4750These commands can take a while depending on the state of the cluster, in any case you can increase
4851the value of ` --command-timeout ` to ` 300 ` or even higher if you receive ` context deadline exceeded ` .
52+
53+ All-in-one script
54+ -----------------
55+
56+ We should execute these commands very carefully, but in a case where you want to execute everything together:
57+
58+ ``` bash
59+ # from inside machine or pod
60+ ETCD=` crictl ps --label io.kubernetes.container.name=etcd --quiet`
61+ crictl exec $ETCD sh -c " etcdctl endpoint status --write-out=table"
62+ REV=` crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl endpoint status --write-out fields" | sed -nE ' s,"Revision" : ([0-9]+),\1,p' `
63+ crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl compact $REV "
64+ crictl exec $ETCD sh -c " unset ETCDCTL_ENDPOINTS && etcdctl defrag $REV --command-timeout 120s"
65+ crictl exec $ETCD sh -c " etcdctl endpoint status --write-out=table"
66+ ```
0 commit comments