One Liner script to delete all pods from the K8s

No alt text provided for this image

Here how the script worked (For those who are beginners and not aware of bash scripting)

  1. kubectl get pods | awk '{print $1}' | tail +2 => awk '{print $1}' will print the first column of the "kubectl get pods" command output which is the list of total number of pods. Further tail +2 is used to remove the column header NAME, or in other words , this will extract the output from the second line onwards. piping(|) is used for re-direction i.e transfer of standard output of one command to next command.
  2. Once we get our desired list of PODs as shown, use | in the previous command and run xargs kubectl delete pod. (kubectl get pods | awk '{print $1'} | tail +2|xargs kubectl delete pod) Here, xargs is a unix command that is used to build and execute command from the standard input.

要查看或添加评论,请登录

Rahul Bhatia的更多文章

  • Handling secrets in AWS ECS using terraform

    Handling secrets in AWS ECS using terraform

    Sometimes, it becomes necessary to remove sensitive information from the terraform template and store the same into AWS…

社区洞察

其他会员也浏览了