NOTE: A self-managed workload cluster cannot delete itself. If your workload cluster is self-managed, you must create a bootstrap cluster and move the cluster lifecycle services to the bootstrap cluster before deleting the workload cluster.

If you did not make your workload cluster self-managed, as described in Make New Cluster Self-Managed, see Delete the workload cluster.

Delete the Pre-provisioned cluster

Follow these steps:

  1. Create a bootstrap cluster:

    The bootstrap cluster will host the Cluster API controllers that reconcile the cluster objects marked for deletion:

    NOTE: To avoid using the wrong kubeconfig, the following steps use explicit kubeconfig paths and contexts.

    dkp create bootstrap --kubeconfig $HOME/.kube/config
    CODE

     ✓ Creating a bootstrap cluster
     ✓ Initializing new CAPI components
    CODE
  2. Move the Cluster API objects from the workload to the bootstrap cluster: The cluster lifecycle services on the bootstrap cluster are ready, but the workload cluster configuration is on the workload cluster. The move command moves the configuration, which takes the form of Cluster API Custom Resource objects, from the workload to the bootstrap cluster. This process is also called a Pivot.

    dkp move capi-resources \
    	--from-kubeconfig ${CLUSTER_NAME}.conf \
    	--from-context ${CLUSTER_NAME}-admin@${CLUSTER_NAME} \
    	--to-kubeconfig $HOME/.kube/config \
    	--to-context kind-konvoy-capi-bootstrapper
    CODE

    ✓ Moving cluster resources
    You can now view resources in the moved cluster by using the --kubeconfig flag with kubectl. For example: kubectl --kubeconfig $HOME/.kube/config get nodes
    CODE

  3. Use the cluster lifecycle services on the workload cluster to check the workload cluster status by running the following command:

    dkp describe cluster --kubeconfig $HOME/.kube/config -c ${CLUSTER_NAME}
    CODE

    NAME                                                                       READY  SEVERITY  REASON  SINCE  MESSAGE
    Cluster/preprovisioned-example                                             True                     2m31s         
    ├─ClusterInfrastructure - PreprovisionedCluster/preprovisioned-example                                            
    ├─ControlPlane - KubeadmControlPlane/preprovisioned-example-control-plane  True                     2m31s         
    │ ├─Machine/preprovisioned-example-control-plane-6g6nr                     True                     2m33s         
    │ ├─Machine/preprovisioned-example-control-plane-8lhcv                     True                     2m33s         
    │ └─Machine/preprovisioned-example-control-plane-kk2kg                     True                     2m33s         
    └─Workers                                                                                                
      └─MachineDeployment/preprovisioned-example-md-0                          True                     2m34s         
        └─Machine/preprovisioned-example-md-0-77f667cd9-tnctd                  True                     2m33s  
    CODE

    NOTE: After moving the cluster lifecycle services to the workload cluster, remember to use dkp with the workload cluster kubeconfig.

    Use dkp with the bootstrap cluster to delete the workload cluster.

  4. Wait for the cluster control-plane to be ready. Run the command below and wait for the condition to be met:

    kubectl --kubeconfig $HOME/.kube/config wait --for=condition=controlplaneready "clusters/${CLUSTER_NAME}" --timeout=20m
    CODE

    cluster.cluster.x-k8s.io/preprovisioned-example condition met
    CODE

Delete the workload cluster

If you have a need to remove the Kubernetes cluster, such as for environment cleanup, use this command to delete the provisioned Kubernetes cluster:

dkp delete cluster --cluster-name=${CLUSTER_NAME}
CODE
✓ Deleting Services with type LoadBalancer for Cluster default/preprovisioned-example
✓ Deleting ClusterResourceSets for Cluster default/preprovisioned-example
✓ Deleting cluster resources
✓ Waiting for cluster to be fully deleted
Deleted default/preprovisioned-example cluster
CODE

Delete the bootstrap cluster

After you have moved the workload resources back to a bootstrap cluster and deleted the workload cluster, you no longer need the bootstrap cluster. You can safely delete the bootstrap cluster with this command:

Delete the kind Kubernetes cluster:

dkp delete bootstrap --kubeconfig $HOME/.kube/config
CODE
✓ Deleting bootstrap cluster
CODE