Monday, 13 August 2018

Shell Script Code To Force Delete Multiple Pods From Kubernetes

ad300
Advertisement
There might be a situation where you have 10 to 20 Pods listed in "terminating status" even when you have issued a delete namespace command. So Now, You may need to force delete all of them. 

But deleting them manually could be a cumbersome job and needs a lot of patience.

Well, there is a way where you can deal with this situation as well:











Code 2➤ Shell Script Code to force delete multiple pods
Create a folder and save below code to your sample.sh file. Now open the git bash and navigate to the folder where you have kept your sample.sh code.

Now run the below command.

➤ sh sample.sh

namespace="yournamespace"
outputPods=($(kubectl get pods -o=name -n $namespace))
podsCount=${#outputPods[@]}
if [ $podsCount -gt 0 ]
then
for (( i=0; i < ${podsCount}; i++ ));
do
   podName=(${outputPods[i]/pod\//})
   echo $(kubectl delete pod ${podName} -n $namespace --grace-period=0 --force)
done
else
   echo "No Pods listed"
fi


Share This
Previous Post
Next Post

Welcome to my blog, I am Subhash Junas, I have been working on Core Java, Ruby, Selenium, Cucumber and on various automation technologies from past couple of years. I love to work on new challenges, solving problems and obstacles.

0 comments: