This topic describes how to delete a Container Service for Kubernetes (ACK) cluster that was created with Terraform, and provides options to retain the necessary resources.
Prerequisites
One of the following clusters have been created with Terraform:
An ACK managed cluster. For more information, see Use Terraform to create an ACK managed cluster.
An ACK dedicated cluster. For more information, see Use Terraform to create an ACK dedicated cluster.
An ACK Edge cluster. For more information, see Use Terraform to create an ACK Edge cluster.
An ACK Serverless cluster. For more information, see Use Terraform to create an ACK Serverless cluster.
Usage notes
When deleting a cluster with Terraform, you can use retain_resources
to retain resources as needed, and you can also configure delete_options
to manage resource deletion and retention.
Category | delete_options | retain_resources |
Methods | Specifies whether to retain or delete specific resources. | Specifies resources to retain. |
Example:
Note You can set
| Example:
Input the resource instance ID into the | |
Supported resources |
|
|
Supported cluster types |
|
|
Step 1: Add resource management parameters
Add the following parameters to the main.tf
file created in the the ACK cluster to control the deletion or retention of resources:
resource "alicloud_cs_managed_kubernetes" "default" { # Add location.
...
// Add the resource instance ID to [].
retain_resources = ["ngw-xxxx"]
// Delete SLB resources created by the cluster.
delete_options {
delete_mode = "delete"
resource_type = "SLB"
}
// Delete ALB resources created by the ALB Ingress Controller.
delete_options {
delete_mode = "delete"
resource_type = "ALB"
}
// Delete the Simple Log Service projects used by the cluster logging feature.
delete_options {
delete_mode = "delete"
resource_type = "SLS_Data"
}
// Delete the Simple Log Service projects used by the managed cluster control plane.
delete_options {
delete_mode = "delete"
resource_type = "SLS_ControlPlane"
}
}
Run the following command to apply the changes:
terraform apply
Step 2: Delete the cluster
You can use the following steps to remove the Terraform-created cluster:
The terraform destroy
command deletes all resources managed by Terraform, which includes irreversible actions such as data deletion. It is crucial to back up any important data and resources before proceeding.
Run the following command to delete the Terraform-created cluster:
terraform destroy
If the following information is returned, type yes, and press Enter. Then, the cluster will be deleted.
... 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 ... Destroy complete! Resources: 7 destroyed.