rubykubernetesconfigmap

How to delete resources by label with Kubeclient?


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?


Solution

  • The accepted answer is outdated. From Kubernetes' kubectl delete documentation:

    Delete resources by file names, stdin, resources and names, or by resources and label selector.

    From that very same documentation page's Examples section:

    # Delete pods and services with label name=myLabel
      kubectl delete pods,services -l name=myLabel