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 1➤ Groovy Code to force delete multiple pods
Create a folder and save below code to your sample.groovy file. Now open the command prompt or git bash and navigate to the folder where you have kept your sample.groovy code.
Now run the below command.
➤ groovy sample.groovy
NOTE: you have to install groovy if it is not installed already
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 1➤ Groovy Code to force delete multiple pods
Create a folder and save below code to your sample.groovy file. Now open the command prompt or git bash and navigate to the folder where you have kept your sample.groovy code.
Now run the below command.
➤ groovy sample.groovy
NOTE: you have to install groovy if it is not installed already
Code 2➤ Shell Script Code to force delete multiple podsnameSpace="yournamespace" getPods="kubectl get pods -o=name -n "+nameSpace+""pods = getPods.execute().text if(!pods.allWhitespace && !pods.equals("No resources found.")){ def podNames = pods.split('\n') for (int i=0; i < podNames.length; i++){ command = "kubectl delete pod "+""+podNames[i].replace( 'pod/', '' ).trim()+""+" -n "+nameSpace+" --grace-period=0 --force" println command.execute().text } }else{ println "No Pods Listed"}
0 comments: