Edit

Share via


AKS cluster deletion fails because a public IP address, subnet, or network security group is in use

Summary

This article explains how to resolve AKS cluster deletion errors such as PublicIPAddressCannotBeDeleted, InUseSubnetCannotBeDeleted, and InUseNetworkSecurityGroupCannotBeDeleted so you can delete the cluster successfully.

Symptoms

When you try to delete an AKS cluster, you receive one of the following error messages:

  • For the PublicIPAddressCannotBeDeleted error code:

    {

    message: "Public IP address ...../providers/Microsoft.Network/publicIPAddresses/ can not be deleted since it is still allocated to resource ...../providers/Microsoft.Network/loadBalancers/kubernetes/frontendIPConfigurations/..... . In order to delete the public IP, disassociate/detach the Public IP address from the resource."

    }

  • For the InUseSubnetCannotBeDeleted error code:

    {

    message: "Subnet aks-subnet is in use by …../Microsoft.Network/networkInterfaces/|providers|Microsoft.Compute|virtualMachineScaleSets|vmss|virtualMachines|1|networkInterfaces|aks-worker-vmss/ipConfigurations/ipconfig1 and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet."

    }

    or

    {

    message: "Subnet aks-subnet is in use by ..../resourceGroups/.../providers/Microsoft.Network/virtualNetworks/.../subnets/.../serviceAssociationLinks/AppServiceLink and cannot be deleted. In order to delete the subnet, delete all the resources within the subnet. See aka.ms/deletesubnet."

    }

  • For the InUseNetworkSecurityGroupCannotBeDeleted error code:

    {

    message: "Network security group …../Microsoft.Network/networkSecurityGroups/test cannot be deleted because it is in use by the following resources: ...../Microsoft.Network/virtualNetworks/test/subnets/test. In order to delete the Network security group, remove the association with the resource(s)."

    }

Cause

The AKS cluster is associated with a subnet, network security group (NSG), or specific public IP address that's currently being used. This association prevents you from deleting the cluster.

Solution