Skip to content

Instantly share code, notes, and snippets.

@nickpoulos
Created November 23, 2021 04:43
Show Gist options
  • Save nickpoulos/51072670c5f78b81183e2f662d3e7750 to your computer and use it in GitHub Desktop.
Save nickpoulos/51072670c5f78b81183e2f662d3e7750 to your computer and use it in GitHub Desktop.
[K8s Delete Pods By Keyword] Delete any running K8s pods containing a keyword #k8s #bash
# kubectl get pods | grep MyServiceName | while read -r line; do $line | awk '{print $1}' | kubectl delete pod $1; done
function delpods() {
local keyword=$1
kubectl get pods | grep $keyword | while read -r line ; do
local containerName=$(awk -v var="$line" '{print $1}')
echo "Deleteing $containerName..."
kubectl delete pod $containerName
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment