Home > Back-end >  Finding out the Kubernetes object that uses the Kubernetes secret
Finding out the Kubernetes object that uses the Kubernetes secret

Time:06-30

I want to know the Object(Deployment/Statefulset/..) which is using a secret. Is there a way to find this out from a secret? Is there a tool in Kubernetes community to do this?

CodePudding user response:

Seems like there is nothing built in, but you can use kubectl in conjuction with jq to figure it out. Here is the example for deployments

kubectl get deployment -o json | jq '.items[] | select(.spec.template.spec.volumes[]? | .secret.secretName=="<secret name>") | .metadata.name'

CodePudding user response:

You can use this command to show the labels of the Object(Deployment/Statefulset) that matches the labels of the Secret

The Pods for example

kubectl get pods [pod_name] --show-labels

or

To get the label of the Secrets

kubectl describe secrets [secret_name]

kubectl get secrets

  • Related