Skip to content

Commit

Permalink
Merge pull request #1548 from arooshap/cric_aps_changes
Browse files Browse the repository at this point in the history
Script for deleting stuck pods in a particular namespace.
  • Loading branch information
arooshap authored Sep 13, 2024
2 parents e07f9ff + a3834fe commit 5d3c55c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions kubernetes/cmsweb/scripts/delete_stuck_pods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Check if the namespace is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <namespace>"
exit 1
fi

namespace=$1

# Get all pods in the namespace that are stuck in "Terminating" state
echo "Finding pods stuck in 'Terminating' state in namespace: $namespace..."

kubectl get pods -n "$namespace" -o json | jq -r '.items[] | select(.metadata.deletionTimestamp != null) | .metadata.name' | while read pod; do
echo "Force deleting pod: $pod in namespace: $namespace"
kubectl delete pod "$pod" -n "$namespace" --grace-period=0 --force
done

0 comments on commit 5d3c55c

Please sign in to comment.