How to Destroy DigitalOcean Kubernetes Clusters

DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service. Deploy Kubernetes clusters with a fully managed control plane, high availability, autoscaling, and native integration with DigitalOcean Load Balancers and volumes. DOKS clusters are compatible with standard Kubernetes toolchains and the DigitalOcean API and CLI.


Destroy a Cluster Using Automation

How to delete a Kubernetes cluster using the DigitalOcean CLI

To delete a Kubernetes cluster via the command-line, follow these steps:

  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token, and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

                  doctl auth init
                
  4. Finally, delete a Kubernetes cluster with doctl kubernetes cluster delete. The basic usage looks like this, but you'll want to read the usage docs for more details:

                  doctl kubernetes cluster delete <id|name>... [flags]
                

    The following example deletes a cluster named example-cluster

                       doctl kubernetes cluster delete example-cluster
                    
How to delete a Kubernetes cluster using the DigitalOcean API

To delete a Kubernetes cluster using the DigitalOcean API, follow these steps:

  1. Create a personal access token, and save it for use with the API.

  2. Send a DELETE request to https://api.digitalocean.com/v2/kubernetes/clusters/{cluster_id}

    cURL

    To delete a Kubernetes cluster with cURL, call:

    
                    curl -X DELETE \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      "https://api.digitalocean.com/v2/kubernetes/clusters/bd5f5959-5e1e-4205-a714-a914373942af"

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To delete a Kubernetes cluster with Godo, use the following code:

    
                    import (
        "context"
        "os"
    
        "github.com/digitalocean/godo"
    )
    
    func main() {
        token := os.Getenv("DIGITALOCEAN_TOKEN")
    
        client := godo.NewFromToken(token)
        ctx := context.TODO()
    
        _, err := client.Kubernetes.Delete(ctx, "bd5f5959-5e1e-4205-a714-a914373942af")
    }

    Ruby

    Ruby developers can use DropletKit, the official DigitalOcean V2 API client for Ruby. To delete a Kubernetes cluster with DropletKit, use the following code:

    
                    require 'droplet_kit'
    token = ENV['DIGITALOCEAN_TOKEN']
    client = DropletKit::Client.new(access_token: token)
    
    client.kubernetes_clusters.delete(id: 'bd5f5959-5e1e-4205-a714-a914373942af')

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    resp = client.kubernetes.delete_cluster(cluster_id="da8fda8")

Destroy a Cluster Using the Control Panel

To destroy a cluster, go to the Kubernetes page in the control panel. From the cluster’s More menu, select Destroy and click Destroy. In the Destroy Kubernetes cluster dialog box, select the resources, such as load balancers and volumes, associated with the cluster to delete them automatically when the cluster is deleted. Enter the name of the cluster, then click Destroy to confirm.

Delete cluster

You can also delete the associated load balancers and volumes manually from the control panel after the cluster is destroyed. You will continue to be billed until the resources are destroyed .

You can also use doctl or the API to delete the associated resources automatically when you destroy a cluster.