Update & Delete Kubernetes resources in one-line command
Have you ever stuck by Kubectl delete? I provide a way to delete metadata.finalizers
quickly.
It recently troubles me that my GKE cluster is managing more and more resources and causing difficulties in maintenance, one of which involves how to delete resources properly.
Next, I will explain step by step the difficulties I encountered in my work and how I finally used the combination of bash commands and kubectl to implement the edition of Kubernetes objects through one-line command.
In general
The following are the basic operations that almost every Kubernetes user takes. Check 👉 the cheatsheet if you’re not familiar with the process.
- Delete a single resource through the
kubectl
command. For example
kubectl delete pod/name-123 -n default
When the action succeeds, the following prompt appears.
pod/name-123 deleted
- But what if hundreds of resources need to be deleted?
It’s not complicated if your resources are with good labels or annotations. You can delete them as long as you find them.
# find the resources and make sure you are…