地形:GKE群集,节点在不同区域

时间:2020-11-01 15:37:24

标签: kubernetes google-cloud-platform terraform google-kubernetes-engine terraform-provider-gcp

我有这个Terraform GKE群集,其中包含3个节点。当我部署该群集时,所有节点都位于europe-west1-b所在的同一区域中。

gke-cluster.yml

resource "google_container_cluster" "primary" {
  name = var.cluster_name

  initial_node_count       = var.initial_node_count

  master_auth {
    username = ""
    password = ""

    client_certificate_config {
      issue_client_certificate = false
    }
  }

  node_config {
    //machine_type = "e2-medium"
    oauth_scopes = [
      "https://www.googleapis.com/auth/logging.write",
      "https://www.googleapis.com/auth/monitoring",
    ]

    metadata = {
      disable-legacy-endpoints = "true"
    }

    labels = {
      app = var.app_name
    }

    tags = ["app", var.app_name]
  }

  timeouts {
    create = "30m"
    update = "40m"
  }
}

variables.tf

variable "cluster_name" {
  default = "cluster"
}

variable "app_name" {
  default = "my-app"
}

variable "initial_node_count" {
  default = 3
}

variable "kubernetes_min_ver" {
  default = "latest"
}

variable "kubernetes_max_ver" {
  default = "latest"
}

variable "remove_default_node_pool" {
  default = false
}

variable "project" {
  default = "your-project-name"
}

variable "credentials" {
  default = "terraform-key.json"
}

variable "region" {
  default = "europe-west1"
}

variable "zone" {
  type        = list(string)
  description = "The zones to host the cluster in."
  default     = ["europe-west1-b", "europe-west1-c", "europe-west1-d"]
}

并且想知道是否可以将每个节点部署在不同的区域中。 如果是的话,如何使用Terraform做到这一点?

1 个答案:

答案 0 :(得分:2)

只需添加以下行

resource "google_container_cluster" "primary" {
  name = "cluster"
  location = "us-central1"
  initial_node_count       = "3"

以便创建regional cluster。上面将显示9个节点,每个区域(fa)包含3个节点。如果每个区域仅需要1个节点,则只需将initial_node_count更改为1。

更多信息here,参见“参数参考”。