All Products
Search
Document Center

Container Service for Kubernetes:Delete an ACK cluster created by Terraform

Last Updated:Nov 15, 2024

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:

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:

delete_options {
 delete_mode = "delete"
 resource_type = "SLS_ControlPlane"
 }
Note

You can set delete_mode to the following values:

  • delete: removes the specified resource type.

  • retain: retains the specified resource type.

Example:

retain_resources = ["ngw-xxxx"]

Input the resource instance ID into the retain_resources parameter. To obtain the instance ID, query the associated resources of the specified cluster.

Supported resources

  • SLB: Server Load Balancer (SLB) resources created for Services. By default, the SLB resources are automatically deleted.

  • ALB: Application Load Balancer (ALB) resources created by the ALB Ingress controller. By default, the ALB resources are retained.

  • SLS_Data: Simple Log Service projects used by the cluster logging feature. By default, the Simple Log Service projects are retained.

  • SLS_ControlPlane: Simple Log Service projects used to store the logs of control planes in ACK managed clusters. By default, the Simple Log Service projects are retained.

  • PrivateZone: PrivateZone resources created by ACK Serverless clusters. By default, the PrivateZone resources are retained.

  • Load balancer (SLB instances of the cluster API server)

  • Internet NAT gateway

  • SNAT entries on an Internet NAT gateway

  • Elastic IP address (Internet NAT gateway)

Supported cluster types

  • ACK managed clusters

  • ACK dedicated clusters

  • ACK Serverless clusters

  • ACK managed clusters

  • ACK Serverless clusters

  • ACK dedicated clusters

  • ACK Edge clusters

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:

Important

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.

  1. Run the following command to delete the Terraform-created cluster:

    terraform destroy
  2. 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.