Azure Kubernetes 服务 - 何时需要在其他 Azure 资源上设置 AKS 服务原则才能建立连接?

Azure Kubernetes Services - when it is required to set AKS Service Principle on other Azure Resources in order to have connection?

默认情况下,在创建 AKS 群集时会为该群集创建一个服务主体。

然后可以在某些其他 Azure 资源(VM?)级别设置该服务主体,以便它们能够建立网络连接并能够进行通信(当然,一般情况除外网络设置)

我真的不确定也无法理解什么时候需要,什么时候不需要。例如,如果我在 VM 级别有数据库,我是否需要授予 AKS 服务主体对 VM 的访问权限才能通过网络与其通信?

有人可以为此提供一些指导,而不是一般文档。什么时候需要 used/set 在那些其他 Azure 资源的级别上,什么时候不需要? 我找不到合适的解释。 谢谢

关于您关于数据库的问题,您不需要授予服务主体对该虚拟机的任何访问权限。鉴于数据库在 Kubernetes 之外运行,不需要以任何方式访问该 VM。数据库甚至可以位于不同的数据中心或完全托管在另一个云提供商上,kubernetes 中的应用程序 运行 仍然能够与其通信,只要流量被防火墙等允许

我知道您没有要求通用文档,但是 Kubernetes Service Principals 上的文档说得很好:

To interact with Azure APIs, an AKS cluster requires either an Azure Active Directory (AD) service principal or a managed identity. A service principal or managed identity is needed to dynamically create and manage other Azure resources such as an Azure load balancer or container registry (ACR).

换句话说,服务主体是 Kubernetes 集群在与其他 Azure 资源交互时进行身份验证的身份,例如:

  • Azure container registry: 创建容器的镜像必须来自某个地方。如果您将自定义图像存储在私有注册表中,则必须授权集群从注册表中提取图像。如果私有注册表是 Azure 容器注册表,则必须为这些操作授权服务主体
  • Networking:Kubernetes 必须能够动态配置路由表并为负载均衡器中的服务注册外部 IP。同样,服务主体用作身份,因此必须经过授权
  • Storage:访问磁盘资源并挂载到pods
  • Azure Container instances:如果您使用虚拟 kubelet 向集群动态添加计算资源,则必须允许 Kubernetes 管理 ACI 上的容器。

delegate access to other Azure resources您可以使用 azure cli 将角色分配给特定范围内的受让人:

az role assignment create --assignee <appId> --scope <resourceScope> --role Contributor

这是a detailed list of all cluster identity permissions正在使用