Skip to content

Instantly share code, notes, and snippets.

@fenar
Created February 18, 2025 04:03
Show Gist options
  • Save fenar/10fe20a66a2369c806b3940708ac07ac to your computer and use it in GitHub Desktop.
Save fenar/10fe20a66a2369c806b3940708ac07ac to your computer and use it in GitHub Desktop.
CleanUp-Zombie-ReplicaSets
#!/bin/bash
# Get all ReplicaSets in all namespaces where no pods are ready (status 0/0)
replicasets=$(oc get rs --all-namespaces --no-headers | awk '$3 == "0" && $4 == "0" {print $1, $2}')
# Loop through the list of ReplicaSets and delete them
echo "$replicasets" | while read namespace rsname
do
echo "Deleting ReplicaSet $rsname in namespace $namespace"
oc delete rs $rsname -n $namespace
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment