Kubernetes kubectl get secrets by type?

How about field-selector:

$ kubectl get secrets --field-selector type=kubernetes.io/tls

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

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