Fabrice Jammes
Fabrice Jammes

Reputation: 3205

How to delete multiple CRDS whose names contain the same string

Can I delete multiple CRDS whose names contain the same string with a kubectl/bash one-liner? For example I'd like to delete all the ones below:

kafkabridges.kafka.strimzi.io
kafkaconnectors.kafka.strimzi.io
kafkaconnects.kafka.strimzi.io
kafkamirrormaker2s.kafka.strimzi.io
kafkamirrormakers.kafka.strimzi.io
kafkarebalances.kafka.strimzi.io
kafkas.kafka.strimzi.io
kafkatopics.kafka.strimzi.io
kafkausers.kafka.strimzi.io

Upvotes: 1

Views: 4057

Answers (3)

Fabrice Jammes
Fabrice Jammes

Reputation: 3205

This one is quite simple and does the job:

MATCH_STRING="kafka.strimzi.io"
kubectl get crds -oname | grep "$MATCH_STRING" | xargs kubectl delete

Upvotes: 5

suren
suren

Reputation: 8786

Same logic; kafka.strimzi.io is the common string:

for crd in `kubectl get crds -oname | grep kafka.strimzi.io | awk -F / '{ print $2 }'`; do kubectl delete crd $crd; done

Upvotes: 2

Adiii
Adiii

Reputation: 59966

All of them seem like contain/ending with kafka.strimzi.io, so the below command should work

 kubectl delete CustomResourceDefinition $(kubectl get CustomResourceDefinition -A | grep "kafka.strimzi.io" | awk '{print $1}')

Upvotes: 1

Related Questions