0

I have the kubectl to delete 1 secret:

kubectl delete -n my_name_space secret secret_name

If I want to delete all secrets of type my_type how can I do that?

Also how can I add filter to delete secrets older than 3 days?

Slava
  • 325
  • 5
  • 13

2 Answers2

2

In order to get secrets of a particular type, you can use --field-selector. Here, is an example:

kubectl get secret --all-namespaces --field-selector type=Opaque   

For deleting resources older than x days, please check this thread. Kubernetes: How to delete PODs based on age/creation time

Emruz Hossain
  • 4,764
  • 18
  • 26
0

Hello to get secret with a specific type :

kubectl get secret --all-namespaces --field-selector type=Opaque 

Also you can get secret older than XXX-date days , you can use this :

kubectl get secrets -o json | jq -r "[.items[] | {name: .metadata.name, startTime: .metadata.creationTimestamp | fromdate } | select(.startTime < (now | . - XXX-date ))]" | jq -r ".[].name"

Don't forget to replace XXX-date by the number of seconds.

rassakra
  • 1,062
  • 5
  • 9