Delete an ACK cluster created by Terraform
Delete a Container Service for Kubernetes (ACK) cluster created with Terraform while keeping the resources that you still need.
Prerequisites
One of the following clusters has been created with Terraform:
Usage notes
When deleting a cluster with Terraform, you can use retain_resources to retain the resources that you need, 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 for the ACK cluster that you created 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"
}
}
Apply the changes:
terraform apply
Step 2: Delete the cluster
Use the following steps to delete 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.
-
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.