Clusters are in Removal Pending state either after disconnecting or destroying your cluster before using 'disconnect Secondary' in k10multicluster tool.

This article helps in finding and deleting long-running finalizers that are waiting on other resources and can cause deletions to appear stuck in terminating state.

Description: 

When Kubernetes attempts to delete the cluster object that has finalizersdist.kio.kasten.io/debootstrap or dist.kio.kasten.io/manual-debootstrap” specified, the Kubernetes API marks the object for deletion by populating .metadata.deletionTimestamp, and returns a 202-status code (HTTP "Accepted"). The cluster object remains in a terminating/Pending state while the control plane, or other components, take the actions defined by the finalizers

Long-running finalizers that are waiting on other resources can cause deletions to appear stuck in terminating state. This is a result of the ServiceAccount (or its corresponding token/bindings) being deleted on the secondary cluster, and 401 or 500 error shown in the k10 dashboard.

Observation: 

K10 multi-cluster dashboard displays ‘Removal Pending’ for primary and secondary clusters, as shown below

 
 
 

 Resolution

Usually, this requires understanding of which API service is not responding and debugging that issue.  

A workaround for the above issue is to remove the clusters by manually deleting the finalizers which are restricting deletion of the cluster. 

Here are the steps to remove an object’s finalizers

  • List down the target cluster. 

# kubectl get clusters.dist.kio.kasten.io -n kasten-io-mc 

  • Delete the target cluster resources by its name.

# kubectl delete clusters.dist.kio.kasten.io ${CLUSTER_NAME} -n kasten-io-mc 

  • Get the finalizer name to be deleted.

# kubectl get cluster.dist.kio.kasten.io -n kasten-io -o yaml 

 
 
  • Manually remove an object’s finalizers by patching the metadata.finalizers field to null

# kubectl patch --namespace=kasten-io-mc clusters.dist.kio.kasten.io ${CLUSTER_NAME} -p '{"metadata":{"finalizers":null}}' --type=merge type=merge 

  

Below command can be used to delete all clusters at once: 

# for x in $(kubectl get clusters.dist.kio.kasten.io -n kasten-io-mc | awk 'NR>1 {print $1}') ; do kubectl patch --namespace=kasten-io-mc clusters.dist.kio.kasten.io $x -p '{"metadata":{"finalizers":null}}' --type=merge ; done