错误:获取处于“已创建”状态的Pod的分配标识失败-AKS AAD-Pod标识

时间:2020-06-18 17:31:22

标签: azure-aks

我在NMI日志中使用托管身份AAD-POD身份收到关于容器(1.14.8)的以下错误。 我已经按照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>

2 个答案:

答案 0 :(得分:1)

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

您可以检查mic服务的日志,并查找以下日志片段“无权执行操作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

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

答案 1 :(得分:0)

确保您配置的身份和绑定与 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 <CLIENT ID>)或 resourceID(例如 az login -i -u <RESOURCE ID>) .


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


要列出群集中的所有 Azure 标识,请运行:

kubectl get azureidentities -A