我试图使用ARM模板创建带有托管标识的AKS容器服务实例。如果我使用az CLI没有问题:
az aks create -g "sa-rg" -n "aks-cluster" --enable-managed-identity
但是,我不能使用ARM模板获得相同的结果。
让我们考虑下面的基本ARM模板
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2021-03-01",
"dependsOn": [],
"location": "australiaeast",
"name": "aks-cluster",
"properties": {
"agentPoolProfiles": [
{
"name": "agentpool",
"count": 1,
"vmSize": "Standard_DS2_v2",
"osType": "Linux",
"osDiskSizeGB": 128,
"`": null,
"osDiskType": "Managed",
"maxPods": 110,
"type": "VirtualMachineScaleSets",
"mode": "System"
}
],
"dnsPrefix": "aks-cluster-dns",
"servicePrincipalProfile": {
"clientId": "msi",
"secret": null
},
"identity": {
"type": "SystemAssigned"
},
"enableRBAC": true
},
"type": "Microsoft.ContainerService/managedClusters"
}
]
}根据https://github.com/Azure/azure-cli/issues/12219#issuecomment-636143374,要用托管标识创建,只需要" identity“对象,而不是"servicePrincipalProfile”。但是,如果我这样做,我会得到以下例外:
错误:{“错误”:{“代码”:“InvalidTemplateDeployment”,“消息”:“根据验证过程,模板部署无效。跟踪id为'5a6c6444-c74b-4709-888e-bef816d05ca9‘。查看内部错误获取详细信息。“,”详细信息“:{”代码“:”InvalidParameter“,”消息“:”为资源组sa-rg中的容器服务aks群集提供资源“。消息:{\n“代码”:"InvalidParameter",\n“消息”:“必需的参数servicePrincipalProfile缺少(Null)。”,\n“目标”:"servicePrincipalProfile"\n }。详情:“}}”
但是,如果我插入"servicePrincipalProfile“(如上面所示),我将得到:
错误:{“错误”:{“代码”:“InvalidTemplateDeployment”,“消息”:“根据验证过程,模板部署无效。跟踪id为'536bca0b-33b8-45f8-8407-edba873d3657‘。查看内部错误获取详细信息。“,”详细信息“:{”代码“:”InvalidParameter“,”消息“:”为资源组sa-rg中的容器服务aks群集提供资源“。消息:{\n“代码”:"InvalidParameter",\n“消息”:“参数servicePrincipalProfile.secret的值是无效的。详细信息请参阅https://aka.ms/aks-naming-rules。“,\n”目标“:"servicePrincipalProfile.secret"\n }。详细信息:”}}“
我试过了
"servicePrincipalProfile": {
"clientId": "msi"
"secret": null
},
"identity": {
"type": "SystemAssigned"
}, "servicePrincipalProfile": {
"clientId": "msi"
"secret": ""
},
"identity": {
"type": "SystemAssigned"
}, "servicePrincipalProfile": {
"clientId": "msi"
"secret": "dummy"
},
"identity": {
"type": "SystemAssigned"
}, "servicePrincipalProfile": {
"clientId": "msi"
},
"identity": {
"type": "SystemAssigned"
},同样的4删除"identity",但是我总是得到参数servicePrincipalProfile.secret的值是无效的。
创建容器服务的正确ARM模板是什么?
发布于 2021-08-21 05:04:05
很少的事情:
identity属性应该位于资源的根,clientId: "msi"属性中指定servicePrincipalProfile。{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2021-03-01",
"dependsOn": [],
"location": "australiaeast",
"name": "aks-cluster",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"agentPoolProfiles": [
{
"name": "agentpool",
"count": 1,
"vmSize": "Standard_DS2_v2",
"osType": "Linux",
"osDiskSizeGB": 128,
"osDiskType": "Managed",
"maxPods": 110,
"type": "VirtualMachineScaleSets",
"mode": "System"
}
],
"dnsPrefix": "aks-cluster-dns",
"servicePrincipalProfile": {
"clientId": "msi"
},
"enableRBAC": true
},
"type": "Microsoft.ContainerService/managedClusters"
}
]
}发布于 2021-08-17 13:37:03
只有当您在ARM模板之外提供服务主体并需要将其属性传递到模板时,servicePrincipalProfile才会被使用。在我的部署中,我已经将它设置为一个空对象,尽管它可能会被完全忽略,因为文档说它不是必需的属性。
"servicePrincipalProfile": {},
"identity": {
"type": "SystemAssigned"
},虽然在我的经验中没有记录它,但是您也可以省略identity属性,它将默认为SystemAssigned。
发布于 2021-09-05 08:22:45
我使用模板部署AKS,模板看起来如下所示。
{
"name": "[parameters('Your-aks-name')]",
"type": "Microsoft.ContainerService/managedClusters",
"apiVersion": "2021-07-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "Basic",
"tier": "Free"
},
"properties": {
"kubernetesVersion": "1.20.7",
"addonProfiles": { ..... },
"enableRBAC": "[parameters('aks_enableRBAC')]",
"dnsPrefix": "[variables('aks-dns-prefix')]",
"agentPoolProfiles": [
{ .... }
],
"servicePrincipalProfile": {
"ClientId": "[parameters('servicePrincipalClientId')]",
"Secret": "[parameters('servicePrincipalClientSecret')]"
},
}
}所以,你可以看到,ClientId和秘密是必要的。
当我运行时,我会得到以下错误。
The value of parameter servicePrincipalProfile.secret is invalid. Please see https://aka.ms/aks-naming-rules for more details.所以我解决了这个问题如下。
首先,创建一个服务原则。它给出了详细的这里。
az ad sp创建-for-rbac--跳过-赋值-名称vivek-脑票证-ask群集-sp
注意应用程序Id和密码。
az ad sp show --id 67def144-ded3-4fe9-a2f1-cdec6689cd2e # use your app id here.此外,创建之后,您可以在蔚蓝门户中看到它们,如下所示。搜索并进入Azure刀片。点击应用程序注册,然后所有应用程序或拥有的应用程序。


如果您忘记记下密码,则必须删除sp,然后重新创建它。
az ad sp delete --id a76ef144-dee3-4fe9-12f1-cdecn689cd2e # use your app id here.因此,对于模板中的servicePrincipalProfile,请执行以下操作。对于客户端id,使用AppId,对于机密,使用密码。
现在试着创造你的知识,看看会发生什么。
https://stackoverflow.com/questions/68817153
复制相似问题