EMK - Delete a Kubernetes cluster
Estimated time to read: 4 minutes
In this tutorial you learn how to delete your Kubernetes cluster through the GUI, kubectl or Terraform.
Be aware that all deployed resources (load balancers, volumes (with RECLAIMPOLICY
delete), containers, deployments, config maps, secrets, etc.) will be deleted.
Deleting an EMK Cluster is straightforward.
Navigate to the EMK Cluster overview in the Fuga dashboard
Here you can find an overview of all your clusters. Click on the three dots "..." and select "Delete cluster". A form will pop up with the request if you are sure to the delete this cluster. Afterwards the deletion will start.
Requirements:
- Kubectl, installation instructions can be found here.
- Service Account (SA), how to get one; See here.
First list your clusters.
% export KUBECONFIG=emk-sa-kubeconfig.yaml
% kubectl get shoots
NAME PROVIDER K8S VERSION LAST OPERATION STATUS AGE
my-cluster openstack 1.28.9 Reconcile Succeeded (100%) healthy 42d
To delete your cluster with kubectl, you need to add an annotation before you can proceed with the deletion.
kubectl annotate shoot my-cluster confirmation.gardener.cloud/deletion=true
shoot.core.gardener.cloud/my-cluster annotated
Now it is possible to delete the cluster. This is possible with:
Now that your cluster is getting deleted, you can check the status of the deletion process by listing your clusters.
Requirements:
- Terraform, installation instructions can be found here.
- Service Account (SA), how to get one; See here.
This Terraform guide assumes the creation of clusters through our creation tutorial; see here.
To delete the cluster it is required to add an annotation to the cluster.yaml
configuration:
Run terraform plan
and terraform apply
.
❯ terraform apply
kubectl_manifest.my_first_cluster: Refreshing state... [id=/apis/core.gardener.cloud/v1beta1/namespaces/ garden-thomas/shoots/my-cluster]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# kubectl_manifest.my_first_cluster will be updated in-place
~ resource "kubectl_manifest" "my_first_cluster" {
id = "/apis/core.gardener.cloud/v1beta1/namespaces/garden-thomas/shoots/my-cluster"
name = "my-cluster"
~ yaml_body = (sensitive value)
~ yaml_body_parsed = <<-EOT
apiVersion: core.gardener.cloud/v1beta1
kind: Shoot
metadata:
+ annotations:
+ confirmation.gardener.cloud/deletion: "true"
name: my-cluster
namespace: garden-thomas
spec:
.............
EOT
# (13 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
kubectl_manifest.my_first_cluster: Modifying... [id=/apis/core.gardener.cloud/v1beta1/namespaces/ garden-thomas/shoots/my-cluster]
kubectl_manifest.my_first_cluster: Modifications complete after 0s [id=/apis/core.gardener.cloud/v1beta1/ namespaces/garden-thomas/shoots/my-cluster]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Then the annotation is applied, now you can delete your cluster with the Terraform destroy command:
❯ terraform destroy
kubectl_manifest.my_first_cluster: Refreshing state... [id=/apis/core.gardener.cloud/v1beta1/namespaces/ garden-thomas/shoots/my-cluster]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# kubectl_manifest.my_first_cluster will be destroyed
- resource "kubectl_manifest" "my_first_cluster" {
- api_version = "core.gardener.cloud/v1beta1" -> null
- apply_only = false -> null
- force_conflicts = false -> null
- force_new = false -> null
- id = "/apis/core.gardener.cloud/v1beta1/namespaces/garden-thomas/shoots/ my-cluster" -> null
- kind = "Shoot" -> null
- live_manifest_incluster = (sensitive value) -> null
- live_uid = "792a844c-7e90-4d61-ad26-7af7c79e9730" -> null
- name = "my-cluster" -> null
- namespace = "garden-thomas" -> null
- server_side_apply = false -> null
- uid = "792a844c-7e90-4d61-ad26-7af7c79e9730" -> null
- validate_schema = true -> null
- wait_for_rollout = true -> null
- yaml_body = (sensitive value) -> null
- yaml_body_parsed = <<-EOT
..................................
EOT -> null
- yaml_incluster = (sensitive value) -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
kubectl_manifest.my_first_cluster: Destroying... [id=/apis/core.gardener.cloud/v1beta1/namespaces/ garden-thomas/shoots/my-cluster]
kubectl_manifest.my_first_cluster: Destruction complete after 0s
Destroy complete! Resources: 1 destroyed.
Now in Terraform the cluster is destroyed, although in the background the cluster is getting deleted. This can take some time.