Kubernetes cluster deletion unregisters the cluster from the Google Distributed Cloud (GDC) air-gapped instance and deletes the workloads, node pools, control plane nodes, and corresponding resources.
Before you begin
To get the permissions needed to delete a Kubernetes cluster, ask your Organization
IAM Admin to grant you the User Cluster Admin role (user-cluster-admin
). This
role is not bound to a namespace.
Delete a Kubernetes cluster and its resources
Complete the following steps to delete a Kubernetes cluster and its resources:
Console
In the navigation menu, select Kubernetes Engine > Clusters.
In the cluster list, click the cluster that you want to delete.
Click delete Delete Cluster.
When prompted, type the given confirmation phrase and click Delete to delete the cluster.
kubectl
Pause the reconciliation for the
Cluster
custom resource of the Kubernetes cluster:kubectl annotate clusters.cluster.gdc.goog/KUBERNETES_CLUSTER_NAME -n platform \ cluster.gdc.goog/paused=true --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
Trigger the deletion of the
Cluster
custom resource of the cluster:kubectl delete clusters.cluster.gdc.goog/KUBERNETES_CLUSTER_NAME -n platform \ --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG --wait=false
Trigger the deletion of all
NodePoolClaim
custom resources in the cluster:kubectl delete --all nodepoolclaims -n NAMESPACE \ --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG --wait=false
This command starts the background deletion of all node pool claims in the cluster.
Delete the
Cluster
custom resource of the cluster:kubectl delete clusters KUBERNETES_CLUSTER_NAME \ -n NAMESPACE --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
This command might take several minutes based on the amount of node pools in the cluster to delete.
Delete the namespace custom resource:
kubectl --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG delete namespace NAMESPACE
Delete the Istio secret in the
istio-system
namespace:kubectl delete secrets istio-remote-secret-KUBERNETES_CLUSTER_NAME -n istio-system \ --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
In some cases, your Istio secret might have a different name. To list your Istio secret and confirm the name, run the following command:
kubectl get secrets -n istio-system \ --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
Remove the address pool claims with the same name as the target Kubernetes cluster, but located in different namespaces:
for j in $(kubectl get addresspoolclaims -A -o custom-columns=:.metadata.namespace --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG); do kubectl delete addresspoolclaims KUBERNETES_CLUSTER_NAME -n $j --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG; done
You can expect to see errors like the following after executing this command:
Error from server (NotFound): addresspoolclaims.system.private.gdc.goog "KUBERNETES_CLUSTER_NAME" not found
Ignore these errors. The command attempts to find all address pool claims with the specified cluster name in all namespaces. Some namespaces don't contain address pool claims with the name, resulting in an error.
Verify that you deleted the namespace of the Kubernetes cluster:
kubectl get namespaces NAMESPACE \ --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
If the namespace is deleted, the output displays an error indicating the namespace is not found. For example:
Error from server (NotFound): namespaces NAMESPACE not found
Unpause the reconciliation for the
Cluster
custom resource of the cluster:kubectl annotate clusters.cluster.gdc.goog/KUBERNETES_CLUSTER_NAME -n platform \ cluster.gdc.goog/paused- --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG
API
To delete a Kubernetes cluster, remove the
Cluster
custom resource from the GDC instance:kubectl delete clusters.cluster.gdc.goog/KUBERNETES_CLUSTER_NAME -n platform \ --kubeconfig ORG_ADMIN_CLUSTER_KUBECONFIG
Replace the following:
KUBERNETES_CLUSTER_NAME
: The name of the cluster to delete.ORG_ADMIN_CLUSTER_KUBECONFIG
: The org admin cluster's kubeconfig path.
Terraform
To delete a Kubernetes cluster using Terraform, run:
terraform destroy -target kubernetes_manifest.cluster-create