無法刪除 Azure 容器執行個體 使用的虛擬網路或子網
本文討論當您刪除虛擬網路 (VNet) 或 Azure 容器執行個體 (ACI) 所使用的子網時所發生的錯誤,並提供因應措施。
徵狀
當您刪除 ACI 所使用的子網時,您會收到類似下列的錯誤:
Failed to delete subnet '<subnet-name>'. Error: 'Subnet /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name> requires any of the following delegations [Microsoft.ContainerInstance/containerGroups] to reference service association link / subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>/serviceAssociationLinks/acisal.'
Subnet <subnet-name> is in use by /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/networkProfiles/aci-network-profile-<network-profile-name>/containerNetworkInterfaceConfigurations/eth0/ipConfigurations/ipconfigprofile and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.
Failed to delete subnet '<subnet-name>'. Error: Subnet <subnet-name> is in use by /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/networkProfiles/aci-network-profile-<network-profile-name>/containerNetworkInterfaceConfigurations/eth0/ipConfigurations/ipconfigprofile/aci-network-profile-<network-profile-name>/eth0/ipconfigprofile and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet.
當您刪除 ACI 所使用的 VNet 時,您會收到下列錯誤:
Failed to delete virtual network '<vnet-name>'. Error: 'Subnet /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name> requires any of the following delegations [Microsoft.ContainerInstance/containerGroups] to reference service association link /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>/serviceAssociationLinks/acisal.'
原因 1:服務關聯鏈接會封鎖刪除 VNET/子網
ACI 所需的子網委派必須參考剩餘的服務關聯連結,以防止刪除 ACI 所使用的 VNet 或子網。
因應措施:刪除服務關聯連結
流覽至 Azure 入口網站 中的子網。
將子網委派變更為 [無]。
使用
az network profile delete
命令刪除網路設定檔,以確定沒有任何網路配置檔連結至子網。如果步驟 3 中的命令失敗,可能會有持續不斷的網路配置檔。 若要刪除持續性網路設定檔,請使用下列命令:
az network profile delete --id resourceIdOfNetworkProfile
如果網路配置檔仍然封鎖子網更新,請嘗試再次將子網委派設定為 None 。
如果上述步驟沒有説明,請嘗試使用指定的 API 版本,例如 2018-10-01 版,透過 Azure CLI 刪除服務關聯連結:
az resource delete --ids /subscriptions/<subscription-id>/resourceGroups/<resourcegroup-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>/providers/Microsoft.ContainerInstance/serviceAssociationLinks/default --api-version 2018-10-01
原因 2:網路設定檔封鎖刪除 VNet/子網
當您移除容器群組時,ACI 在容器群組建立期間所建立的網路配置檔可能不會正確刪除。 這會導致 VNet 或子網中剩餘的專案,這會封鎖特定的刪除作業。
因應措施 1:從 Azure 入口網站 刪除容器群組的網路配置檔
刪除所有 ACI 容器群組之後,請遵循下列步驟:
- 移至資源群組。
- 選 取 [顯示隱藏的類型]。 根據預設,網路配置檔會隱藏在 Azure 入口網站 中。
- 選取與容器群組相關的網路配置檔。
- 選取 [刪除]。
- 刪除 VNet 或子網。
因應措施 2:透過 Azure CLI 刪除容器群組的網路配置檔
刪除所有 ACI 容器群組之後,請遵循下列步驟:
取得網路設定檔識別碼:
NetworkProfile=$(az network vnet subnet show -g $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME -o tsv --query ipConfigurationProfiles[].id)
移除網路設定檔:
az network profile delete --ids $NetworkProfile --yes
刪除子網:
az network vnet subnet delete --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME
刪除 VNet:
az network vnet delete --resource-group $RES_GROUP --name $SUBNET_NAME
因應措施 3:透過 Azure CLI 更新 containerNetworkInterfaceConfigurations 屬性
如果透過 Azure 入口網站 和 Azure CLI 刪除網路設定檔失敗,請將網路設定檔屬性containerNetworkInterfaceConfigurations
更新為空白清單:
取得網路設定檔識別碼:
NETWORK_PROFILE_ID=$(az network profile list --resource-group <resource-group-name> --query [0].id --output tsv)
更新網路設定檔:
az resource update --ids $NETWORK_PROFILE_ID --set properties.containerNetworkInterfaceConfigurations=[]
刪除網路配置檔和子網。
與我們連絡,以取得說明
如果您有問題或需要相關協助,請建立支援要求,或詢問 Azure community 支援。 您也可以將產品意見反應提交給 Azure 意應見反社群。