Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete kubernetes node pull with Terraform without cluster recreating

I have created DigitalOcean Kubernetes cluster with additional node pull. Everything works great.

resource "digitalocean_kubernetes_cluster" "k8s_cluster" {
  depends_on = [digitalocean_container_registry.docker_registry]
  name    = "dev"
  region  = var.region
  version = "1.30.2-do.0"
  registry_integration = true

  node_pool {
    name       = "dev-pool"
    size       = "s-2vcpu-2gb"
    auto_scale = true
    min_nodes  = 2
    max_nodes  = 4

  }
}

resource "digitalocean_kubernetes_node_pool" "new_k8s_node_pool" {
  cluster_id = digitalocean_kubernetes_cluster.k8s_cluster.id

  name       = "dev-pool-new"
  size       = "s-2vcpu-4gb"
  auto_scale = true
  min_nodes  = 2
  max_nodes  = 4
}

But now I want to delete old node pull (dev-pool) and keep the cluster working with the new node pool (dev-pool-new). But when I do terraform plan I can see that terraform is going to recreate cluster with the new node pull. I don’t want to recreate cluster, I just want to delete default node pool and keep only new node pull. How can I do that? Is it available to delete default node pull without cluster recreating?

resource "digitalocean_kubernetes_cluster" "k8s_cluster" {
  depends_on = [digitalocean_container_registry.docker_registry]
  name    = "dev"
  region  = var.region
  version = "1.30.2-do.0"
  registry_integration = true

  node_pool {
    name       = "dev-pool-new"
    size       = "s-2vcpu-4gb"
    auto_scale = true
    min_nodes  = 2
    max_nodes  = 4

  }
}

terraform plan output samples:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

digitalocean_kubernetes_cluster.k8s_cluster must be replaced

digitalocean_kubernetes_node_pool.new_k8s_node_pool will be destroyed

>Solution :

The cluster must be re-created if the default node pool (the block node_pool within digitalocean_kubernetes_cluster) is modified for certain parameters. This is a requirement enforced by the Digital Ocean API.

If you want to modify a node pool without cluster re-creation, then you must use the additional node pool resource instead.

resource "digitalocean_kubernetes_node_pool" "new" {
  cluster_id = digitalocean_kubernetes_cluster.k8s_cluster.id

  name       = "dev-pool-new"
  size       = "s-2vcpu-4gb"
  auto_scale = true
  min_nodes  = 2
  max_nodes  = 4
}

Note that for your current cluster you cannot remove the default node pool without causing a cluster re-creation, but can add the new node pool.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading