# Uninstall in-cluster 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.29/docs/overview.md.txt).

> [!CAUTION]
> **Caution:** In-cluster Cloud Service Mesh using the `ISTIOD` control plane on GKE on Google Cloud is [deprecated](https://docs.cloud.google.com/service-mesh/deprecations.md.txt). Cloud Service Mesh with an in-cluster control plane on Google Distributed Cloud (software only) continues to be supported as described in [Supported platforms](https://docs.cloud.google.com/service-mesh/v1.29/docs/supported-platforms.md.txt#off-gcp).

This page explains how to uninstall in-cluster 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.29/docs/overview.md.txt)
to understand the differences.

Following these instructions to uninstall in-cluster Cloud Service Mesh
removes all configurations.

If you are uninstalling managed Cloud Service Mesh, follow the
[managed uninstallation guide](https://docs.cloud.google.com/service-mesh/v1.29/docs/uninstall-managed.md.txt) instead.

If you are migrating from in-cluster to managed, follow the
[Migration guide](https://docs.cloud.google.com/service-mesh/v1.29/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.

1. To prevent interrupting application traffic:

   - Downgrade any STRICT mTLS policies to PERMISSIVE.
   - Remove any AuthorizationPolicy that may block traffic.
2. 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.

   > [!NOTE]
   > **Note:** You should also check resources including Deployments, StatefulSets, ReplicaSets, DaemonSets, Jobs and CronJobs also for injection.

3. Restart your workloads that have sidecars injected to remove the proxies.

4. Delete the `validatingwebhooksconfiguration` and
   `mutatingwebhookconfiguration` from your cluster, if they exist:

   ```bash
     kubectl delete validatingwebhookconfiguration,mutatingwebhookconfiguration -l operator.istio.io/component=Pilot,istio.io/owned-by!=mesh.googleapis.com
   ```
5. 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.
6. Optionally, Remove Istio CRs, Isto CRDs, istio-(revision) configmap,
   asm-options configmap, `istio-system` and `asm-system` namespaces to remove
   service mesh from the cluster or use them in another Istio API compatible
   service mesh.

   1. Remove Istio CRs:

      ```bash
      kubectl delete gateways,virtualservices,destinationrules,serviceentries,envoyfilters,sidecars,peerauthentications,requestauthentications,authorizationpolicies,telemetries,wasmplugins,proxyconfigs --all --all-namespaces
      ```
   2. Remove Istio CRDs:

      ```bash
      kubectl get crds -o name | grep --color=never 'istio.io' | xargs kubectl delete
      ```
   3. Remove istio-(revision) configmap. You can skip this step if you delete
      the `istio-system` namespace.

      ```bash
      kubectl delete configmap istio-RELEASE_CHANNEL -n istio-system
      ```

      Replace <var translate="no">RELEASE_CHANNEL</var> with your release channel
   4. Remove `istio-system` namespace:

      ```bash
      kubectl delete namespace istio-system --ignore-not-found=true
      ```
   5. Remove `asm-system` namespace:

      ```bash
      kubectl delete namespace asm-system --ignore-not-found=true
      ```
      1. 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.

         ```sh
          NAME                 STATUS       AGE
          istio-system         Terminating  71m
          asm-system           Terminating  71m
          ```
         ````
7. 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.

8. 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.

Once you've completed 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.