karthikeayan
karthikeayan

Reputation: 5000

How to find which role or clusterrole binded to a service account in Kubernetes?

Is there a way with kubectl to find out which clusterroles or roles are bound to the service account?

Upvotes: 16

Views: 8252

Answers (1)

Esteban Garcia
Esteban Garcia

Reputation: 2283

You could do something like:

kubectl get rolebindings,clusterrolebindings \
  --all-namespaces  \
  -o custom-columns='KIND:kind,NAMESPACE:metadata.namespace,NAME:metadata.name,SERVICE_ACCOUNTS:subjects[?(@.kind=="ServiceAccount")].name' | grep "<SERVICE_ACCOUNT_NAME>"

Replace the grep with then name of the service account you are looking for.

Upvotes: 34

Related Questions