Skip to content

Commit 1f958e0

Browse files
authored
updating cheatsheet.md with command to get containerIDs of all initContainer (#19243)
* adding cheatsheet.md adding kubectl command to get containerIDs of all initContainers for every Pod in the cluster helps to identify stopped container which should not be removed, when running manual cleanup of stopped containers on K8s cluster nodes * adding more context for finding initContainer IDs * removing reference to github issue Signed-off-by: Anastas Dancha <[email protected]>
1 parent 9e5b981 commit 1f958e0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

content/en/docs/reference/kubectl/cheatsheet.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.ty
191191
# List all Secrets currently in use by a pod
192192
kubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq
193193

194+
# List all containerIDs of initContainer of all pods
195+
# Helpful when cleaning up stopped containers, while avoiding removal of initContainers.
196+
kubectl get pods --all-namespaces -o jsonpath='{range .items[*].status.initContainerStatuses[*]}{.containerID}{"\n"}{end}' | cut -d/ -f3
197+
194198
# List Events sorted by timestamp
195199
kubectl get events --sort-by=.metadata.creationTimestamp
196200

0 commit comments

Comments
 (0)