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

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

kubectl 有没有办法找出哪些 clusterroles 或角色绑定到服务帐户?

你可以这样做:

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>"

将 grep 替换为您要查找的服务帐户的名称。