【问题标题】:error: getting assigned identities for pod in CREATED state failed - AKS AAD-Pod identity错误:为处于 CREATED 状态的 pod 分配身份失败 - AKS AAD-Pod 身份
【发布时间】:2021-06-18 05:26:43
【问题描述】:

我在使用托管标识 AAD-POD 标识的 aks (1.14.8) 的 NMI 日志中收到以下 pod 错误。 我已按照https://github.com/Azure/aad-pod-identity 中指定的步骤进行操作,但我们希望将托管标识用于 azure sql paas。 参考链接:https://trstringer.com/connect-k8s-apps-msi/

E0618 17:19:40.762387 1 server.go:370] failed to get matching identities for pod: default/schedulerserviceapi-7fc4dc9547-95vbw, error: getting assigned identities for pod default/schedulerserviceapi-7fc4dc9547-95vbw in CREATED state failed after 16 attempts, retry duration [5]s. Error: <nil>

【问题讨论】:

    标签: azure-aks


    【解决方案1】:

    可能的原因是您的集群服务主体没有角色Managed Identity Operator

    可以查看mic服务的日志,查找如下日志sn -p "not have permission to perform action Microsoft.ManagedIdentity/userAssignedIdentities/assign/action'"

    您可以使用以下 CLI 命令将角色分配给服务主体:

    # retrieve cluster service principal clientId ($SP_CLIENT_ID below)
    az aks show -g $RESOURCE_GROUP -n $AKS_CLUSTER_NAME --query servicePrincipalProfile.clientId -o tsv
    
    # assign role to SP
    az role assignment create --role "Managed Identity Operator" --assignee $SP_CLIENT_ID  --scope /subscriptions/$SUBSCRIPTION_ID/resourcegroups/$RESOURCE_GROUP
    

    参考:https://github.com/Azure/aad-pod-identity/issues/585

    【讨论】:

    • 请注意,如果集群是使用托管标识而不是服务主体创建的,您可能需要调整 az aks show 命令
    【解决方案2】:

    确保您配置的身份和绑定与 pod 匹配。

    阅读更多:Best PracticesDemo

    在下面找到使用多个 AzureIdentities 的 pod 示例。

    AzureIdentities

    apiVersion: aadpodidentity.k8s.io/v1
    kind: AzureIdentity
    metadata:
      name: az-id-1
    spec:
      type: 0
      resourceID: <ResourceID of az-id-1>
      clientID: <ClientID of az-id-1>
    
    apiVersion: aadpodidentity.k8s.io/v1
    kind: AzureIdentity
    metadata:
      name: az-id-2
    spec:
      type: 0
      resourceID: <ResourceID of az-id-2>
      clientID: <ClientID of az-id-2>
    

    AzureIdentityBinding

    apiVersion: aadpodidentity.k8s.io/v1
    kind: AzureIdentityBinding
    metadata:
      name: az-id-1-binding
    spec:
      azureIdentity: az-id-1
      selector: az-id-combined
    
    apiVersion: aadpodidentity.k8s.io/v1
    kind: AzureIdentityBinding
    metadata:
      name: az-id-2-binding
    spec:
      azureIdentity: az-id-2
      selector: az-id-combined
    

    吊舱

    apiVersion: v1
    kind: Pod
    metadata:
      name: demo
      labels:
        aadpodidbinding: az-id-combined
    ...
    

    注意:如果您未指定要使用的托管标识(例如 az login -i),则将随机选择与 aadpodidbinding 选择器匹配的托管标识之一。为确保将正确的托管标识用于特定工作负载,请确保在进行身份验证时指定托管标识的 clientId(例如 az login -i -u &lt;CLIENT ID&gt;)或 resourceID(例如 az login -i -u &lt;RESOURCE ID&gt;)。


    查看deploy/demo 的文件以获取更多示例。


    要列出集群中的所有 Azure 身份,请运行:

    kubectl get azureidentities -A
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 2021-11-29
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 2022-06-30
      相关资源
      最近更新 更多