Home > Net >  How to delete resources by label with Kubeclient?
How to delete resources by label with Kubeclient?

Time:10-15

I am trying to delete multiple ConfigMaps at once using a label. With kubectl, I would do it as follow:

kubectl delete cm -l application=my-app

Kubeclient offers the delete_config_map method, but it requires a name.

# `k` is an instance of Kubeclient::Client
k.delete_config_map('my-config-map')

Is there a way to acheive the same behavior as the CLI here?

CodePudding user response:

The way kubectl does operations upon labeled, versus named, resources is that it actually does that in two phases: get -o name $resourceType -l ... and then the actual requested operation upon ${those_resource_names}

One can run kubectl --v=10 (or the v of your choice) to see it in action

Since that behavior is a feature of kubectl and not the kubernetes API itself, it means anyone trying to replicate that handy feature will need to replicate the two-phase approach also

  • Related