Delete Tanzu Kubernetes Clusters

To delete a Tanzu Kubernetes cluster, run the tanzu cluster delete command. Depending on the cluster contents and cloud infrastructure, you may need to delete in-cluster volumes and services before you delete the cluster itself.

Step One: List Clusters

To list all of the Tanzu Kubernetes clusters that a management cluster is managing, run the tanzu cluster list command.

tanzu cluster list

Step Two: Delete Volumes and Services

If the cluster you want to delete contains persistent volumes or services such as load balancers and databases, you may need to manually delete them before you delete the cluster itself. What you need to pre-delete depends on your cloud infrastructure:

  • vSphere

  • Amazon EC2

    • Load Balancers: Application or Network Load Balancers (ALBs or NLBs) in the cluster’s VPC, but not Classic Load Balancers (ELB v1). Delete these resources in the AWS UI or with the kubectl delete command.
    • Other Services: Any subnet and EC2-backed service in the cluster’s VPC, such as an RDS or VPC, and related resources such as:

      • VPC: Delete under VPC Dashboard > Virtual Private Cloud > Your VPCs.
      • RDS: Delete under RDS Dashboard > Databases.
      • Subnets: Delete under VPC Dashboard > Virtual Private Cloud > Subnets.
      • Route Tables: Delete under VPC Dashboard > Virtual Private Cloud > Route Tables.
      • Internet Gateways: Delete under VPC Dashboard > Virtual Private Cloud > Internet Gateways.
      • Elastic IP Addresses: Delete under VPC Dashboard > Virtual Private Cloud > Elastic IPs.
      • NAT Gateways: Delete under VPC Dashboard > Virtual Private Cloud > NAT Gateways.
      • Network ACLs: Delete under VPC Dashboard > Security > Network ACLs.
      • Security Groups: Delete under VPC Dashboard > Security > Security Groups.

      Delete these resources in the AWS UI as above or with the aws CLI.

    • Persistent Volumes and Persistent Volume Claims: Delete these resources with the kubectl delete command as described in Delete Persistent Volume Claims and Persistent Volumes, below.

  • Azure

    • No action required. Deleting a cluster deletes everything that TKG created in the cluster’s resource group.

Delete Service type LoadBalancer

To delete Service type LoadBalancer (Service) in a cluster:

  1. Set kubectl to the cluster’s context.

    kubectl config use-context my-cluster@user
    
  2. Retrieve the cluster’s list of services.

    kubectl get service
    
  3. Delete each Service type LoadBalancer.

    kubectl delete service <my-svc>
    

Delete Persistent Volumes and Persistent Volume Claims

To delete Persistent Volume (PV) and Persistent Volume Claim (PVC) objects in a cluster:

  1. Run kubectl config use-context my-cluster@user to set kubectl to the cluster’s context.

  2. Run kubectl get pvc to retrieve the cluster’s Persistent Volume Claims (PVCs).

  3. For each PVC:

    1. Run kubectl describe pvc <my-pvc> to identify the PV it is bound to. The PV is listed in the command output as Volume, after Status: Bound.

    2. Run kubectl describe pv <my-pv> to describe to determine if its bound PV Reclaim Policy is Retain or Delete.

    3. Run kubectl delete pvc <my-pvc> to delete the PVC.

    4. If the PV reclaim policy is Retain, run kubectl delete pv <my-pvc> and then log into your cloud portal and delete the PV object there. For example, delete a vSphere CNS volume from your datastore pane > Monitor > Cloud Native Storage > Container Volumes. For more information about vSphere CNS, see Getting Started with VMware Cloud Native Storage.

Step Three: Delete Cluster

  1. To delete a cluster, run tanzu cluster delete.

    tanzu cluster delete my-cluster
    

    If the cluster is running in a namespace other than the default namespace, you must specify the --namespace option to delete that cluster.

    tanzu cluster delete my-cluster --namespace=my-namespace
    

    To skip the yes/no verification step when you run tanzu cluster delete, specify the --yes option.

    tanzu cluster delete my-cluster --namespace=my-namespace --yes
    

    Amazon EC2: to delete a cluster on Amazon EC2, the AWS_REGION variable must be set to the region where the cluster is running.
    You can set AWS_REGION in the local environment or credential profile, as described in Configure AWS Account Credentials.
    Or to delete the cluster in a different region, prepend the setting to the tanzu cluster delete command:

    AWS_REGION=eu-west-1 tanzu cluster delete my-cluster
    

Important: Do not change context or edit the .kube-tkg/config file while Tanzu Kubernetes Grid operations are running.

check-circle-line exclamation-circle-line close-line
Scroll to top icon