Skip to content

Instantly share code, notes, and snippets.

@xsqian
Last active September 14, 2023 17:41
Show Gist options
  • Save xsqian/6b82f7731540f9bb2dfd6b05dcec08d0 to your computer and use it in GitHub Desktop.
Save xsqian/6b82f7731540f9bb2dfd6b05dcec08d0 to your computer and use it in GitHub Desktop.
How to delete all the pods that are in Completed status in a k8s
kubectl get pod --field-selector=status.phase==Succeeded
kubectl delete pod --field-selector=status.phase==Succeeded
kubectl delete pod --field-selector=status.phase==Failed
kubectl delete pods $(kubectl get pod --all-namespaces -o jsonpath='{.items[?(@.status.containerStatuses[*].state.waiting.reason=="CrashLoopBackOff")].metadata.name}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment