//Cloud notes from my desk -Maheshk

"Fortunate are those who take the first steps.” ― Paulo Coelho

Failed to delete virtual network ‘k8s-vkdemo-2-vnet’. Error: Subnet virtual-node-aci is in use by and cannot be deleted

Recently I tried deleting few resource groups(RG) having AKS cluster with ACI enabled. I couldn’t get them deleted completely for some reason leaving Vnet all those RG’s.

Error message was “Failed to delete virtual network ‘k8s-vkdemo-2-vnet’. Error: Subnet virtual-node-aci is in use by and cannot be deleted.” I got the same error for other 2 cluster RG as well. I tried deleting individual sub-nets there I got an error.

With help of support and this article I was able to delete the RG. It’s is documented here -> https://docs.microsoft.com/en-us/azure/container-instances/container-instances-vnet#delete-network-resources.

Here is the revised script.

# Replace <my-resource-group> with the name of your resource group
RES_GROUP=<my-resource-group>

# Replace <my_vnet_name> with the name of your VNet name
VNET_NAME=<my_vnet_name>

# Replace <my_subnet_name> with the name of your subnet name
SUBNET_NAME=<my_subnet_name>

# Get network profile ID
NETWORK_PROFILE_ID=$(az network profile list --resource-group $RES_GROUP --query [0].id --output tsv)

# Delete the network profile
az network profile delete --id $NETWORK_PROFILE_ID -y

# Get the service association link (SAL) ID
SAL_ID=$(az network vnet subnet show --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME --query id --output tsv)/providers/Microsoft.ContainerInstance/serviceAssociationLinks/default

# Delete the default SAL ID for the subnet
az resource delete --ids $SAL_ID --api-version 2018-07-01

# Delete the subnet delegation to Azure Container Instances
az network vnet subnet update --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME--remove delegations 0

# Delete the subnet
az network vnet subnet delete --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME

# Delete virtual network
az network vnet delete --resource-group $RES_GROUP --name $VNET_NAME
Advertisements

2019-03-18 - Posted by | AKS, Azure, Azure Dev, Uncategorized

No comments yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: