Skip to content
Snippets Groups Projects
k8s-pods-cleaner.sh 481 B
Newer Older
#! /bin/sh

#
# Clean kubernetes pods stuck in "Terminating" state
#
# Example:
#
PERFORM="$2"
for pod in $(kubectl get pod -n "$NS" | awk 'NR>1 && $3=="Terminating" {print $1}'); do
	if [ -n "$PERFORM" ]; then
		kubectl get pod -n "$NS" "$pod" -oyaml > "/tmp/$NS-$pod.yaml"
		kubectl delete pod -n "$NS" "$pod" --force
	else
		kubectl get pod -n "$NS" "$pod"
	fi
done