From 1f958e0744a3b56f5c4daa6d29029dea8b3ca7a7 Mon Sep 17 00:00:00 2001 From: Anastas Dancha Date: Mon, 16 Mar 2020 09:12:35 +0300 Subject: [PATCH] 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 --- content/en/docs/reference/kubectl/cheatsheet.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/en/docs/reference/kubectl/cheatsheet.md b/content/en/docs/reference/kubectl/cheatsheet.md index 38d723e981..8401d00ecf 100644 --- a/content/en/docs/reference/kubectl/cheatsheet.md +++ b/content/en/docs/reference/kubectl/cheatsheet.md @@ -191,6 +191,10 @@ JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.ty # List all Secrets currently in use by a pod kubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq +# List all containerIDs of initContainer of all pods +# Helpful when cleaning up stopped containers, while avoiding removal of initContainers. +kubectl get pods --all-namespaces -o jsonpath='{range .items[*].status.initContainerStatuses[*]}{.containerID}{"\n"}{end}' | cut -d/ -f3 + # List Events sorted by timestamp kubectl get events --sort-by=.metadata.creationTimestamp