Using Terraform to provision GKE how to prevent google_container_cluster resource from scaling

8/26/2018

I have a working terraform declaration with one google_container_cluster and one google_container_node_pool

When my kubectl deployment creates pressure on the node another google_container_node_pool is spawned automatically.

How do I control this [limit to one or n node pools per cluster]

I could only find a way to limit the nodes within the node_pool their min and max values are set to 1

resource "google_container_node_pool" "rtp_container_cluster_node_pool" 
{
  name = "node-pool"
  zone = "${var.zone}"
  cluster = "${google_container_cluster.rtp_container_cluster.name}"

  node_config {
    machine_type = "${var.machine_type_node}"
    disk_size_gb = "${var.disk_size_gb_node}"
    local_ssd_count = "${var.local_ssd_count_node}"
    oauth_scopes = "${var.oauth_scopes}"
  }


  # Autoscale
  autoscaling {
    min_node_count = "${var.minNodeCount_node}"
    max_node_count = "${var.maxNodeCount_node}"
  }
}



resource "google_container_cluster" "rtp_container_cluster" {
  name = "${var.container_cluster_name}-master"
  zone = "${var.zone}"
  initial_node_count = "${var.cluster_count}"
  additional_zones = "${var.additional_zones}"
  network = "${var.network}"
  subnetwork = "${var.subnetwork}"
  enable_kubernetes_alpha = "${var.enable_kubernetes_alpha}"
  min_master_version = "${var.min_master_version}"

  master_auth {
    username = "${var.username}"
    password = "${var.password}"
  }

  node_config {
    machine_type = "${var.machine_type}"
    disk_size_gb = "${var.disk_size_gb}"
    local_ssd_count = "${var.local_ssd_count}"
    oauth_scopes = "${var.oauth_scopes}"
    tags = "${var.tags}"

    labels {
      purpose = "dev-rtp-poc-cluster"
    }
  }

  addons_config {
    http_load_balancing {
      disabled = "${var.http_load_balancing_disable}"
    }

    horizontal_pod_autoscaling {
      disabled = "${var.horizontal_pod_autoscaling_disable}"
    }
  }

}

-- Rubber Duck
google-cloud-platform
google-kubernetes-engine
kubernetes
terraform

1 Answer

8/27/2018

Autoscaling works on the Node Pool level. There is no system within GKE that will automatically create a new Node Pool. If you would just like to have one node per cluster, I would suggest to just set the initial node count to "1" and completely disable Autoscaling, as it is not needed in your use case.

-- Jason
Source: StackOverflow