Unable to delete AKS cluster
Unable to delete an unused cluster. I've been trying it for a couple of days but couldn't do it.
VNet, subnet, public IP resources are already deleted.
Recieved this error everytime I try to delete the cluster.
(DNCCleanupServiceError) Failed to clean up pod networking resources.
Code: DNCCleanupServiceError
Message: Failed to clean up pod networking resources.
Can someone please have a look?
Azure Kubernetes Service (AKS)
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-04-29T02:11:09.5566667+00:00 Hi UV Panta,
Based on your query,
Could you please check for remaining resources ensure there is no resource should be link check by using below commandkubectl get pods --all-namespaces kubectl get services --all-namespaces kubectl get deployments --all-namespaces
Please refer the documentation for more information on commands
https://kubernetes.io/docs/reference/kubectl/generated/kubectl_get/#examples
If you found anything delete them manuallyAs you mentioned in query it is already deleted but based on error it is link some other resource networking better try to check for any remaining network interfaces, IP configurations, or delegated subnet entries that might still be linked to the cluster's pods. Manually delete any of these unused resources to allow the cluster deletion process to complete successfully
If above things are not working, try to use below command force to delete the cluster
az aks delete --name <cluster-name> --resource-group <resource-group-name> --yes --no-wait
Please refer the documentation for more information on command line
https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-deleteAlso, check that the user or identity has the Contributor role on the AKS resource group, as this role is required to manage and delete the cluster.
Please refer the below documentation and community question and answer it is also related to some kind of issue cluster it might help any one point
https://learn.microsoft.com/en-us/troubleshoot/azure/azure-kubernetes/create-upgrade-delete/cannot-delete-ip-subnet-nsg
https://github.com/Azure/AKS/issues/2443Try the steps mentioned above and let me know how it goes. If you have any further questions or need assistance, please let me know
-
UV Panta • 0 Reputation points
2025-04-29T03:36:05.18+00:00 Hey Akshay,
Thanks for your response.While trying to delete namespace or any other resources, I get this message:
Failed to load all namespaces.The same happens with workloads & services.
Also the cli returns following error.
{"code":"BadRequest","details":null,"message":"ManagedCluster is in a state preventing RunCommand feature: PowerState=Running ProvisioningState=Deleting","subcode":""}
Now, I tried to delete using the command above with the flags --yes --no-wait, but it's still in deleting state and not completed.
I checked the other links. In my case, there's no subnet nsg or any other resource. All of them are already deleted.
Can you suggest what else should I do?
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-04-29T07:32:30.2666667+00:00 Hi UV Panta,
Thanks for reply and tried on previous steps.
Just wanted you to check when you create an AKS cluster, it automatically creates another resource group. This second group, with the prefix nameMC_<resourcegroupname>
, contains all the network and related configurations, if it is still present delete this resource as shown in the screenshot below nameIf you know about the second MC resource group already deleted the resources in it, that would be great!
Can you check the status of your cluster's provisioning state once, you can use the following command:
az aks show -n <cluster-name> -g <resource-group>
If the cluster is in a transitional state (such as
Updating
orDeleting
) or if there’s an inconsistency in its provisioning state, the deletion might fail or become stuck.And also, you can run the command below to see what is causing the issue by adding --debug command
az aks delete -n <clustername> -g <resourcegroup> --debug
I found another community question and answer about deleting a cluster. Over there, they found the issue and were able to delete the cluster by using the debug command. Please refer below link
-
UV Panta • 0 Reputation points
2025-04-30T01:30:50.49+00:00 I checked them, the cluster is in failed state.
There's no any additional message than the one from I shared above.Is there any other way to force delete the cluster? The no-wait flag didn't way.
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-04-30T04:53:57.61+00:00 Hi UV Panta,
Have you checked the second resource group, MC_<resourcegroup>? Ensure that all resources in this resource group have been deleted, as this might be causing the issue with the network resources could you please confirm on this? -
UV Panta • 0 Reputation points
2025-04-30T06:39:48.0266667+00:00 yes, the MC_ resource group and all the resources inside are already deleted.
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-04-30T09:22:04.2633333+00:00 Hi UV Panta,
Thanks for confirming,
And, as you mentioned previously cluster is currently in a Failed state, and you've already attempted deletion can you please try below commands to delete cluster First, list the node pools to ensure they're still present:az aks nodepool list --resource-group <resourcegroup> --cluster-name <clusterame>
Then, delete each node pool individually using the following command:
az aks nodepool delete --resource-group <rg-name> --cluster-name <cluster-name> --name <nodepool-name>
Please refer the below documentation for command line
Delete a node poolDelete the AKS Cluster via REST API try using the Azure REST API directly with the Azure CLI. You can get the full resource URI from the JSON view of the cluster in the Azure Portal.
az rest --method delete --uri \"https://management.azure.com/subscriptions/<sub-id>/resourceGroups/<rg-name>/providers/Microsoft.ContainerService/managedClusters/<cluster-name>?api-version=2024-01-01"
Please refer the document for more information rest API
Resources - Delete
Check the Azure Activity Logs to see if any additional messages or errors are present. This can help identify if there are any new issues or dependencies preventing the deletion of the cluster -
UV Panta • 0 Reputation points
2025-04-30T23:57:17.84+00:00 Hi Akshay,
I can see the list of the node-pools. When I tried to delete the nodepool, following error occured:
`(OperationNotAllowed) Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
Code: OperationNotAllowed
Message: Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
Now, when trying to delete using REST method, the command ran but it didn't delete the cluster.
-
UV Panta • 0 Reputation points
2025-05-01T14:08:21.3933333+00:00 Hi,
Can anyone help me on this please?This issue is still pending and I'm unable to delete the cluster at all.
I never thought of experience with Azure would be so unpleasant.
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-05-02T08:14:51.67+00:00 Hi UV Panta,I
The cluster might be in a transient state. But we don't know the exact issue at this moment, and we can't confirm what was the issue
Can you try once below command
az aks operation-abort --name myAKSCluster --resource-group myResourceGroup you can use at the end of the command flag --debug to get more logs. once it done reconcile the cluster using this command: az aks update --resource-group <resource-group-name> --name <aks-cluster-name>Please refer the community Q&A & Please let me know
https://learn.microsoft.com/en-us/answers/questions/1529162/aks-is-stuck-in-pending-deleting-operation -
UV Panta • 0 Reputation points
2025-05-02T08:21:55.9066667+00:00 Hi @Akshay kumar mandha
The first comand returned this error:
(OperationNotAllowed) Cancel operation is not allowed when the ProvisioningState is Failed. The terminated operation started at '2025-04-30T23:55:32Z' and elapsed time is: '1 days and 08:25:19' (RFC3339 format)
Code: OperationNotAllowed
Message: Cancel operation is not allowed when the ProvisioningState is Failed. The terminated operation started at '2025-04-30T23:55:32Z' and elapsed time is: '1 days and 08:25:19' (RFC3339 format)
-
Akshay kumar Mandha • 2,915 Reputation points • Microsoft External Staff
2025-05-02T09:33:52.29+00:00 Hi UV Panta,
Here your cluster is failed state so it is not applying the command if it is pending or ongoing it might works based on your error message have check below command both are getting same error message can you confirm please
az aks update --resource-group <resource-group-name> --name <aks-cluster-name> -
UV Panta • 0 Reputation points
2025-05-02T13:30:28.3733333+00:00 It gave the same error:
cli.azure.cli.core.azclierror: (OperationNotAllowed) Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
Code: OperationNotAllowed
Message: Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
az_command_data_logger: (OperationNotAllowed) Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
Code: OperationNotAllowed
Message: Cannot run operation because deletion has been initiated on the cluster. The only allowed operation after deletion has started is to retry cluster deletion.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x102a667a0>]
az_command_data_logger: exit code: 1
cli.main: Command ran in 6.157 seconds (init: 0.082, invoke: 6.076)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
Sign in to comment