Delete the deployment and pods under remote k8s in batches through keywords under windows

Article directory

1 needs

  • There are too many pods on the test environment server, insufficient resources, and normal pods cannot be started. Many pods are created based on github pr events and need to be deleted, but the k8s UI interface is very slow to delete one by one

  • I feel that under the busy work, I need a completely non-utilitarian thing to give myself inner energy. Blogging is one of them. Blogging seems to be a non-utilitarian contact with the outside world. No wonder I need to take time to do some outdoor sports. It really makes people more energetic

2 Operation steps

  • Install K8S, support kubectl command
  • Find the yaml file of the remote k8s config (you can ask for it from the operation and maintenance)
  • Open git bash in the directory where the file is located, and execute the command:
  • kubectl --kubconfig configuration file get deployments -n environment namespace | grep keyword | awk '{print 1}' | xargs kubectl --kubeconfig configuration file | delete deployment -n environment namespace
    insert image description here

3 note

  • After deleting the deployment, the pods will be deleted together

Guess you like

Origin blog.csdn.net/lanxing_huangyao/article/details/123676252