我正在使用 Azure Bicep 创建具有单个子网的 virtualNetwork,然后将其用作创建 aks 集群的输入:vnetSubnetID: virtualNetwork.properties.subnets[0].id
我第一次运行该命令时,它可以很好地创建虚拟网络和集群,但是第二次运行该命令时,它会给出以下错误:
{"error":{"code":"InvalidTemplateDeployment","message":"根据验证程序,模板部署 'cluster' 无效。跟踪 id 是 '[REDACTED_JUST_IN_CASE]'。有关详细信息,请参阅内部错误。 ","details":[{"code":"PropertyChangeNotAllowed","message":"资源组showcase-kevinplayground2 中容器服务playground-cluster0 的资源配置失败。消息:{\n "code": "PropertyChangeNotAllowed",\n "message": "不允许更改属性 'agentPoolProfile.vnetSubnetID'。",\n "target": "agentPoolProfile.vnetSubnetID"\n }。详细信息: "}]}}
我仔细检查了一下,部署创建的 virtualNetwork 中只有一个子网(没有其他神奇的出现或任何东西)。
我在第二个资源组上重复了这个实验,同样的事情发生了,所以它是可重现的。
这是完整的二头肌文件(只需调用az deployment group create --resource-group showcase-kevinplayground2 -f cluster.bicep
您选择的资源组)
targetScope = 'resourceGroup'
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-02-01' = {
name: 'aksVirtualNetwork'
location: resourceGroup().location
properties:{
addressSpace:{
addressPrefixes:[
'10.10.0.0/16'
]
}
subnets:[
{
name: 'aks'
properties:{
addressPrefix: '10.10.5.0/24'
}
}
]
}
}
resource aksManagedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: 'playgroundIdentity'
location: resourceGroup().location
}
resource aks 'Microsoft.ContainerService/managedClusters@2021-02-01' = {
name: 'playground-cluster0'
location: resourceGroup().location
identity: {
type:'UserAssigned'
userAssignedIdentities: {
'${aksManagedIdentity.id}': {}
}
}
sku: {
name: 'Basic'
tier: 'Free'
}
properties: {
kubernetesVersion: '1.21.2'
dnsPrefix: 'playground'
enableRBAC: true
networkProfile: {
networkPlugin: 'azure'
networkPolicy: 'calico'
}
aadProfile: {
managed: true
enableAzureRBAC: true
}
autoUpgradeProfile: {}
apiServerAccessProfile: {
enablePrivateCluster: false
}
agentPoolProfiles: [
{
name: 'aksnodes'
count: 1
vmSize: 'Standard_B2s'
osDiskSizeGB: 30
osDiskType: 'Managed'
vnetSubnetID: virtualNetwork.properties.subnets[0].id
osType: 'Linux'
maxCount: 1
minCount: 1
enableAutoScaling: true
type: 'VirtualMachineScaleSets'
mode: 'System'
orchestratorVersion: null
}
]
}
}