<a id="co-delete-deployment"></a>

# Delete Confluent Platform Deployment Using Confluent for Kubernetes

When you shut down a Confluent for Kubernetes (CFK) deployment, the components and resources
must be deleted in the following order:

<a id="co-delete-order"></a>
1. [Delete the Confluent application resources](#co-delete-application-resources).
2. [Delete the Confluent Platform components](#co-delete-cp-components).
3. [Delete the CFK](#co-delete-cfk).

If you encounter an orphaned custom resource that are stuck in the Deleting
state, see [Issue: Unable to delete Kubernetes resources](co-troubleshoot-known-issues.md#co-orphaned-resource) for the troubleshooting steps.

#### NOTE
Do not use the `--force` option when issuing the `kubectl delete`
command. With the option, the underlying resource will not be properly
deleted.

To delete a CFK and Confluent Platform deployment:

<a id="co-delete-application-resources"></a>

## Delete the Confluent application resources

The CFK application resources include the following:

* ClusterLink
* ConfluentRolebinding
* Connector
* KafkaTopic
* SchemaExporter
* Schema
* KafkaRestClass

To delete the Confluent application resources:

1. Check which of the CFK resources were deployed and locate their CRs.
   ```bash
   kubectl get confluent --namespace <namespace>
   ```

   An example output is:
   ```bash
   NAME                                        REPLICAS   READY   STATUS    AGE
   kafka.platform.confluent.io/kafka           3          3       RUNNING   23h

   NAME                                        REPLICAS   READY   STATUS    AGE
   connect.platform.confluent.io/connect       2          2       RUNNING   23h

   NAME                                                AGE
   kafkarestclass.platform.confluent.io/krc-cfk-mtls   24h
   ```
2. Delete the application custom resources (CRs) using one of the following
   commands.
   * Using the CR file:
     ```bash
     kubectl delete -f <application CR> --namespace <namespace>
     ```
   * Using the resource name from Step 1:
     ```bash
     kubectl delete <resource name> --namespace <namespace>
     ```

     For example:
     ```bash
     kubectl delete kafkarestclass.platform.confluent.io/krc-cfk-mtls --namespace <namespace>
     ```

<a id="co-delete-cp-components"></a>

## Delete the Confluent Platform components

The best practice to delete a CFK deployment is to follow the [recommended
order](#co-delete-order).

If you choose to not follow the best practice order of deletion, you can try
using  the `--cascade=foreground` option with the `kubectl` command to
delete resource with dependencies. The option deletes the dependent resource
before it deletes the component cluster. For example, when deleting a Connect
cluster associated with a connector that did not get deleted in the
[previous step](#co-delete-application-resources), the
`--cascade=foreground` option deletes the connector resource, first, and
then deletes the Connect cluster.

For more information, see [Use Cascading Deletion in a
Cluster](https://kubernetes.io/docs/tasks/administer-cluster/use-cascading-deletion/).

To delete the Confluent Platform component clusters:

1. Delete the Confluent Platform component CRs, excluding Kafka and ZooKeeper.

   The CFK component resources include the following:
   * Connect
   * ControlCenter
   * KafkaRestProxy
   * KsqlDB
   * SchemaRegistry
   * USMAgent

   <br/>

   Delete the resources using one of the following commands.
   * Using the CR file:
     ```bash
     kubectl delete -f <component CR> --namespace <namespace>
     ```
   * Using the resource name from Step 1:
     ```bash
     kubectl delete <resource name> --namespace <namespace>
     ```

     For example:
     ```bash
     kubectl delete connect.platform.confluent.io/connect --namespace <namespace>
     ```
2. Delete Kafka using one of the following commands.
   ```bash
   kubectl delete -f <Kafka CR> --namespace <namespace>
   ```

   or
   ```bash
   kubectl delete <Kafka resource name> --namespace <namespace>
   ```
3. Delete ZooKeeper using one of the following commands.

   #### IMPORTANT
   Starting with Confluent Platform version 8.0, ZooKeeper is no longer part of Confluent Platform.

   ```bash
   kubectl delete -f <Zookeeper CR> --namespace <namespace>
   ```

   or
   ```bash
   kubectl delete <Zookeeper resource name> --namespace <namespace>
   ```

<a id="co-delete-cfk"></a>

## Delete the CFK

To delete the CFK:

1. Check the release name of your CFK.
   ```bash
   helm ls --namespace <namespace>
   ```
2. Using the release name you retrieved in the previous step, delete the
   CFK.
   ```bash
   helm delete <CFK release name> --namespace <namespace>
   ```
3. Delete the namespace.
   ```bash
   kubectl delete namespace <namespace>
   ```
