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
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
0 comments: