Use kubectl or the Tanzu CLI to delete a TKG cluster.

When you delete a TKG cluster using kubectl or the Tanzu CLI, Kubernetes garbage collection ensures that all dependent resources are deleted.
Note: Do not attempt to delete a cluster using the vSphere Client or the vCenter Server CLI.

Procedure

  1. Authenticate with the Supervisor.
  2. Change context to the vSphere Namespace where the TKG you want to delete is provisioned.
    kubectl config use-context CLUSTER-NAMESPACE
  3. List the TKG clusters in the namespace.
    kubectl get clusters
    tanzu cluster list
  4. Delete the TKG cluster using the following syntax.
    v1alpha3 cluster using kubectl:
    kubectl delete tanzukubernetescluster --namespace CLUSTER-NAMESPACE CLUSTER-NAME
    v1beta1 cluster using kubectl:
    kubectl delete cluster --namespace CLUSTER-NAMESPACE CLUSTER-NAME
    v1alpha3 or v1beta1 cluster using the Tanzu CLI:
    tanzu cluster delete --namespace CLUSTER-NAMESPACE CLUSTER-NAME
    Example result:
    tanzukubernetescluster.run.tanzu.vmware.com "tkg-cluster-1" deleted
  5. Verify that the cluster is deleted.
    kubectl:
    kubectl get clusters
    Tanzu CLI:
    tanzu cluster list
  6. Delete the cluster context from the kubeconfig file.
    kubectl config delete-context CONTEXT
    For example:
    kubectl config get-contexts
    CURRENT   NAME            CLUSTER         AUTHINFO                                        NAMESPACE
              192.0.2.1       192.0.2.1       wcp:192.0.2.1:[email protected]
              tkg-cluster-1   192.0.2.6       wcp:192.0.2.6:[email protected]
    *         tkg-ns-1        192.0.2.7       wcp:192.0.2.7:[email protected]       tkg-ns-1
    
    kubectl config delete-context tkg-cluster-1
    deleted context tkg-cluster-1 from $HOME/.kube/config
    
    kubectl config get-contexts
    CURRENT   NAME            CLUSTER        AUTHINFO                                       NAMESPACE
              192.0.2.1       192.0.2.1      wcp:192.0.2.1:[email protected]
    *         tkg-ns-1        192.0.2.7       wcp:192.0.2.7:[email protected]     tkg-ns-1