Skip to content

Commit e04be31

Browse files
authored
Added an "all in one" script for etcd defrag/compact (openshift#71134)
1 parent 3029216 commit e04be31

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

docs/dptp-triage-sop/etcd-slowness.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,37 @@ Once inside the master we can execute the following commands:
3030
sudo -i
3131
# get etcd container id
3232
ETCD=`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

4750
These commands can take a while depending on the state of the cluster, in any case you can increase
4851
the 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

Comments
 (0)