如何在Kubernetes中找到绑定到服务帐户的角色或集群角色?

kar*_*yan 3 permissions rbac kubernetes

kubectl是否有办法找出服务帐户绑定了哪些集群角色或角色?

Est*_*cia 7

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>"
Run Code Online (Sandbox Code Playgroud)

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