Remove Defender for Containers from Arc-enabled clusters

This article explains how to remove Defender for Containers from your Arc-enabled Kubernetes clusters. Follow these steps when you need to completely uninstall the service or troubleshoot deployment issues.

When you enable Defender for Containers capabilities that use automatic provisioning, or use recommendations to manually deploy container capabilities on specific resources, you install Defender components and extensions in your environment.

If you decide to stop using those capabilities, you might also want to remove these components from your environment. This article helps you understand the actions you can take to remove them.

Note

To remove this (or any) Defender for Cloud extension, you need more than just turning off automatic provisioning:

  • When you turn on automatic provisioning, it can affect existing and future machines.
  • When you turn off automatic provisioning for an extension, it only affects future machines. Nothing gets uninstalled when you turn off automatic provisioning.

Remove Arc extensions from clusters

You can remove extensions by using the Azure portal, Azure CLI, or REST API.

  1. In the Azure portal, open Azure Arc.

  2. In the infrastructure list, select Kubernetes clusters, then select the specific cluster.

  3. Open the Extensions page, which lists extensions on the cluster.

  4. Select the microsoft.azuredefender.kubernetes extension, then select Uninstall.

    Screenshot that shows the button for uninstalling an extension from an Azure Arc-enabled Kubernetes cluster.

  5. Repeat for the azurepolicy extension if installed.

Disconnect clusters from Azure Arc

Warning

Only disconnect from Azure Arc if you no longer use any Arc-enabled services on the cluster.

To disconnect a cluster from Azure Arc:

az connectedk8s delete \
    --name <cluster-name> \
    --resource-group <resource-group> \
    --yes

Disable Defender plan

Using Azure portal

  1. Go to Microsoft Defender for Cloud > Environment settings.

  2. Select your subscription.

  3. On the Defender plans page, toggle Containers to Off.

  4. Select Save.

Verify removal

Check Azure resources

az k8s-extension list \
    --cluster-type connectedClusters \
    --cluster-name <cluster-name> \
    --resource-group <resource-group>

Check cluster resources

kubectl get pods -n kube-system -l app=microsoft-defender

No pods should be returned after successful removal.