Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

Save Resources in K8s, Delete Failed Pods

#!/bin/bash
# This script check the passed namespace and delete pods in 'CrashLoopBackOff state 
NAMESPACE="test"
delpods=$(sudo kubectl get pods -n ${NAMESPACE} |
  grep -i 'CrashLoopBackOff' |
  awk '{print $1 }')    
for i in ${delpods[@]}; do
sudo kubectl delete pod $i --force=true --wait=false 
    --grace-period=0 -n ${NAMESPACE} 
done
Source by faun.pub #
 
PREVIOUS NEXT
Tagged: #Save #Resources #Delete #Failed #Pods
ADD COMMENT
Topic
Name
6+3 =