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
?
How about filed-selector:
$ kubectl get secrets --field-selector type=kubernetes.io/tls
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
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