Reputation: 1750
I want to run kubectl and get all the secrets of type = X. Is this possible?
I.e if I want to get all secrets where type=tls
something like kubectl get secrets --type=tls
?
Upvotes: 21
Views: 10324
Reputation: 341
How about field-selector:
$ kubectl get secrets --field-selector type=kubernetes.io/tls
Upvotes: 34
Reputation: 61551
You can do it jsonpath
. Something like this:
$ kubectl get secret -o=jsonpath='{range .items[*]}{.metadata.name} {.type}{"\n"}{end}' | grep -i tls
For example, to get all the type Opaque
secrets:
$ kubectl get secret -o=jsonpath='{range .items[*]}{.metadata.name} {.type}{"\n"}{end}' | grep Opaque
dummy-secret Opaque
mysecretdelete Opaque
Update:
Now you can do this with the --field-selector
option in kubectl
:
$ kubectl get secrets --field-selector type=kubernetes.io/tls
$ kubectl get secret --field-selector type=kubernetes.io/service-account-token
Upvotes: 16
Reputation: 691
The accepted answer certainly works, but I was interested in finding a grep
-less solution. Here's my contribution.
$ kubectl get secret -o=jsonpath='{.items[?(@.type=="Opaque")].metadata.name}'
dummy-secret mysecretdelete
Upvotes: 6