# Uninstall Cloud Service Mesh

> [!NOTE]
> **Note:** This guide only supports Cloud Service Mesh with Istio APIs and does not support Google Cloud APIs. For more information see, [Cloud Service Mesh overview](https://docs.cloud.google.com/service-mesh/v1.27/docs/overview.md.txt).

This page explains how to uninstall Cloud Service Mesh if you are using
the Istio APIs. If you are using Compute Engine APIs, no steps are
necessary. See the [Cloud Service Mesh overview](https://docs.cloud.google.com/service-mesh/v1.27/docs/overview.md.txt)
to understand the differences.

Following these instructions to uninstall Cloud Service Mesh removes
all configurations regardless of control plane type (in-cluster or managed).
If you are doing a migration from in-cluster to managed, follow the
[Migration guide](https://docs.cloud.google.com/service-mesh/v1.27/docs/tutorials/migrate-in-cluster-to-managed-on-new-cluster.md.txt)
instead.

## Uninstall Cloud Service Mesh

Use the following commands to uninstall all Cloud Service Mesh components. These
commands also delete the `istio-system` namespace and all custom resource
definitions (CRDs), including any CRDs that you applied.

> [!WARNING]
> **Warning:** If you created CRDs, make sure you have copies of them before proceeding through the following steps.

1. To prevent interruption of application traffic:

   - Downgrade any STRICT mTLS policies to PERMISSIVE.
   - Remove any AuthorizationPolicy that may block traffic.
2. Disable Automatic Management on this cluster (whether you applied it
   directly or using the fleet-default configuration):

         gcloud container fleet mesh update \
            --management manual \
            --memberships MEMBERSHIP_NAME \
            --project FLEET_PROJECT_ID \
            --location MEMBERSHIP_LOCATION

   Replace the following:
   - <var translate="no">MEMBERSHIP_NAME</var> is the membership name listed when you verified that your cluster was registered to the fleet.
   - <var translate="no">MEMBERSHIP_LOCATION</var> is the location of your membership (either a region, or `global`).
3. Disable sidecar auto-injection on your namespace(s), if it is enabled. Run
   the following command to display namespace labels:

   ```bash
    kubectl get namespace YOUR_NAMESPACE --show-labels
   ```

   The output is similar to the following:

   <br />

   ```bash
    NAME   STATUS   AGE     LABELS
    demo   Active   4d17h   istio.io/rev=asm-181-5
   ```

   <br />

   If you see `istio.io/rev=` in the output under the `LABELS` column,
   remove it:

   ```bash
    kubectl label namespace YOUR_NAMESPACE istio.io/rev-
   ```

   If you see `istio-injection` in the output under the `LABELS` column,
   remove it:

   ```bash
    kubectl label namespace YOUR_NAMESPACE istio-injection-
   ```

   If you don't see either the `istio.io/rev` or `istio-injection` labels,
   then auto-injection wasn't enabled on the namespace.
4. Restart your workloads that have sidecars injected to remove the proxies.

5. If you're using managed Cloud Service Mesh, check which
   [control plane implementation](https://docs.cloud.google.com/service-mesh/v1.27/docs/supported-features-managed.md.txt#identify_control_plane_implementation)
   you have in your cluster, this will help delete relevant resources in further
   steps.

6. If you're using managed Cloud Service Mesh, remove all `controlplanerevision`
   resources in the cluster:

   ```bash
   kubectl delete controlplanerevision asm-managed asm-managed-rapid asm-managed-stable -n istio-system --ignore-not-found=true
   ```

   Check the status of the `controlplanerevision` resources to verify they were
   deleted:

   ```bash
   kubectl get controlplanerevision -n istio-system
   ```

   If the output shows that a `controlplanerevision` resource is still present,
   it might be stuck with the `mesh.cloud.google.com/deprovision` finalizer. In
   this case, you can manually remove the finalizer from the resource to allow
   it to be deleted:

   ```bash
   kubectl patch controlplanerevision CPR_NAME -n istio-system -p '{"metadata":{"finalizers":null}}' --type=merge
   ```

   Replace <var translate="no">CPR_NAME</var> with the name of the control plane revision
   returned in the previous step, for example, `asm-managed`.
7. Delete webhooks from your cluster, if they exist.

   ### In-cluster Cloud Service Mesh

   Delete the `validatingwebhooksconfiguration` and `mutatingwebhookconfiguration`.

   ```bash
   kubectl delete validatingwebhookconfiguration,mutatingwebhookconfiguration -l operator.istio.io/component=Pilot,istio.io/owned-by!=mesh.googleapis.com
   ```

   ### Managed Cloud Service Mesh

   A. Delete the `validatingwebhooksconfiguration`.

   ```bash
   kubectl delete validatingwebhookconfiguration istiod-istio-system-mcp
   ```

   B. Delete all `mutatingwebhookconfiguration`.

   > [!NOTE]
   > **Note:** Use the `RELEASE_CHANNEL` according to the [release channel](https://docs.cloud.google.com/service-mesh/v1.27/docs/managed/release-channels) you provisioned. For example, Regular(`istiod-asm-managed`), Rapid (`istiod-asm-managed-rapid`), and Stable (`istiod-asm-managed-stable`).

       kubectl delete mutatingwebhookconfiguration istiod-RELEASE_CHANNEL

8. Once all workloads come up and no proxies are observed, then you can safely
   delete the in-cluster control plane to stop billing.

   To remove the in-cluster control plane, run the following command:

   ```bash
   istioctl uninstall --purge
   ```

   If there are no other control planes, you can delete the `istio-system`
   namespace to get rid of all Cloud Service Mesh resources. Otherwise, delete the
   services corresponding to the Cloud Service Mesh revisions. This avoids deleting
   shared resources, such as CRDs.
9. Delete the `istio-system` and `asm-system` namespaces:

   ```bash
    kubectl delete namespace istio-system asm-system --ignore-not-found=true
   ```
10. Check if the deletions were successful:

    ```bash
     kubectl get ns
    ```

    The output should indicate a `Terminating` state and return as shown,
    otherwise you might have to manually delete any remaining resources in
    the namespaces and try again.

    ```bash
     NAME                 STATUS       AGE
     istio-system         Terminating  71m
     asm-system           Terminating  71m
    ```
11. If you will delete your clusters, or have already deleted them, ensure
    that each cluster is
    [unregistered](https://docs.cloud.google.com/anthos/fleet-management/docs/unregister) from your fleet.

12. If you enabled managed Cloud Service Mesh fleet-default configuration and
    want to disable it for future clusters, disable it. You can skip this step
    if you're only uninstalling from a single cluster.

    ```bash
     gcloud container hub mesh disable --fleet-default-member-config --project FLEET_PROJECT_ID
    ```

    Where <var translate="no">FLEET_PROJECT_ID</var> is the ID of your Fleet Host project.
13. If you plan to stop using Cloud Service Mesh at the fleet level, disable the service mesh feature for your fleet host project.

    ```bash
     gcloud container hub mesh disable --project FLEET_PROJECT_ID
    ```

    Where <var translate="no">FLEET_PROJECT_ID</var> is the ID of your Fleet Host project.
14. If you enabled managed Cloud Service Mesh, check and delete managed resources if they present:

    > [!NOTE]
    > **Note:** If your cluster is an `Autopilot` cluster, you cannot delete resources from the `kube-system` namespace. If you're uninstalling managed Cloud Service Mesh and you're keeping your cluster, [contact Support](https://docs.cloud.google.com/service-mesh/v1.27/docs/getting-support.md.txt) to ensure that these resources are deleted.

    1. Delete the `mdp-controller` deployment:

       ```bash
         kubectl delete deployment mdp-controller -n kube-system
       ```
    2. Get then delete the data plane control custom resource:

       1. Get the data plane control CR:

          ```bash
          kubectl get dataplanecontrol
          ```
       2. Delete the data plane control CR:

          ```bash
          kubectl delete dataplanecontrol DATA_PLANE_CONTROL_CR_NAME
          ```

          Replace <var translate="no">DATA_PLANE_CONTROL_CR_NAME</var> with the output from
          the previous command.
       3. Delete the `controlplanerevision` and dataplanecontrol CRDs:

          ```bash
          kubectl delete crd controlplanerevisions.mesh.cloud.google.com dataplanecontrols.mesh.cloud.google.com
          ```
    3. If you have the `TRAFFIC_DIRECTOR` control plane implementation, clean up Transparent Health Check resources. Normally these are removed automatically, but you can make sure they are cleaned up by doing the following:

       1. Delete the `snk` daemonset.

          ```bash
             kubectl delete daemonset snk -n kube-system
          ```
       2. Delete the firewall rule.

          ```bash
             gcloud compute firewall-rules delete gke-csm-thc-FIRST_8_CHARS_OF_CLUSTER_ID
          ```

          Replace the following:
          - <var translate="no">FIRST_8_CHARS_OF_CLUSTER_ID</var> is the first 8 characters of the Cluster ID for your specific cluster.
    4. Check to see if the `istio-cni-plugin-config` configmap is present:

       ```bash
         kubectl get configmap istio-cni-plugin-config -n kube-system
       ```

       If present, delete the `istio-cni-plugin-config` configmap:

       ```bash
         kubectl delete configmap istio-cni-plugin-config -n kube-system
       ```

       > [!WARNING]
       > **Warning:** The network reliability of your GKE cluster may be impacted if you don't delete this configmap.

    5. Delete the `istio-cni-node` daemonset:

       ```bash
         kubectl delete daemonset istio-cni-node -n kube-system
       ```
15. If you're uninstalling managed Cloud Service Mesh, [contact Support](https://docs.cloud.google.com/service-mesh/v1.27/docs/getting-support.md.txt) to ensure that all
    Google Cloud resources are cleaned up. The `istio-system` namespace and config
    maps may also continue to be recreated if you don't follow this step.

Upon completion of these steps, all Cloud Service Mesh components, including proxies,
in-cluster certificate authorities, and RBAC roles and bindings, are
systematically removed from the cluster. During the installation process, a
Google-owned service account is granted the necessary permissions to establish
the service mesh resources within the cluster. These uninstall instructions
don't revoke these permissions, allowing for a seamless re-activation of
Cloud Service Mesh in the future.

> [!NOTE]
> **Note:** Some resources (e.g. Network Endpoint Groups or NEGs) will be orphaned after the systematic removal of these components. To err on the side of caution, Cloud Service Mesh must *fail open* during clean up. This is to ensure that the uninstallation of managed Cloud Service Mesh never has a negative impact other networking resources in your project or on the workloads. To have these orphaned resources removed for the purposes of hygiene or "house cleaning", contact [Google Cloud Support](https://docs.cloud.google.com/service-mesh/v1.27/docs/getting-support.md.txt)