# Delete a cluster

Delete a cluster and its machines, keeping it restorable for 7 days or keeping nothing.

Replace _my-cluster_ with your cluster's name or id.

**Warning:**
A permanent delete keeps nothing: no final snapshot, and the PersistentVolumes are deleted with
their data. The cluster cannot be restored.

## Prerequisites

- Permission for `eks:DeleteCluster` on the cluster; to turn deletion protection off,
  `eks:UpdateClusterConfig`.
- Deletion protection off. While it is on, the delete answers `409` "Deletion protection is on.
  Turn it off in the cluster’s settings first."
- In the console, also `eks:DescribeCluster` to open the cluster.

## Turn deletion protection off

**Console**
1. Open **Kubernetes**, open the cluster, then choose **Danger zone**.
2. Under **Deletion protection**, choose **Turn off**. The change is saved at once.

**CLI**
```sh
dcloud eks clusters update my-cluster --no-deletion-protection
```

**API**
```http
PATCH /eks/api/clusters/my-cluster
{ "deletionProtection": false }
```

**Terraform**
Set `deletion_protection = false` on the `dcloud_eks_cluster` and apply.

## Delete the cluster

**Console**
1. On the cluster's **Danger zone**, under **Delete this cluster**, (optional) select **Delete
   permanently: keep nothing (no snapshot, volumes deleted with their data)**.
2. Choose **Delete cluster**.
3. In the dialog, enter the cluster name, and choose **Delete cluster**.

The console returns to the cluster list.

**CLI**
```sh
dcloud eks clusters delete my-cluster
```

To keep nothing: `--permanent true`.

**API**
```http
DELETE /eks/api/clusters/my-cluster
```

To keep nothing: `?permanent=true`.

**Terraform**
Remove the `dcloud_eks_cluster` and apply. Set `delete_permanently = true` beforehand to keep
nothing.

## Result

The answer is `{ id, status: "deleting", permanent }`. Deleting a cluster already being deleted
answers `{ id, status: "deleting" }` and changes nothing: a `permanent` sent then is ignored. Deutsche Cloud then removes the machines, the node groups and
their nodes, the endpoint load balancer, the firewalls and the load balancers of the cluster's
LoadBalancer Services. Each step is in **Activity**.

**By default**, a final etcd snapshot is taken first. For 7 days the cluster is listed under
**Recently deleted** on the **Kubernetes** page and can be restored: its settings, key material and
PersistentVolumes are kept, the volumes detached and not billed. See
[Restore a deleted cluster](restore-a-deleted-cluster.md). If the final snapshot cannot be taken
and verified, nothing is kept and the cluster cannot be restored.

**Permanently**, nothing is kept.

## Related

- [Restore a deleted cluster](restore-a-deleted-cluster.md)
- `eks.clusters.delete` · `dcloud eks clusters delete` · `dcloud_eks_cluster`
