From 6300383b4368b52f855603970e6ba6b33d80023f Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Sat, 4 Nov 2017 10:57:12 -0700 Subject: [PATCH] Change worker managed instance group to span zones in region * Change Google Cloud module to require the `region` variable * Workers are created in random zones within the given region * Tolerate Google Cloud zone failures or capacity issues * If workers are preempted (if enabled), replacement instances can be drawn from any zone in the region, which should avoid scheduling issues that were possible before if a single zone aggressively preempts instances (presumably due to Google Cloud capacity) --- CHANGES.md | 5 +++++ README.md | 1 + docs/google-cloud.md | 2 ++ docs/index.md | 1 + .../container-linux/kubernetes/cluster.tf | 2 +- .../container-linux/kubernetes/variables.tf | 7 ++++++- .../kubernetes/workers/variables.tf | 4 ++-- .../container-linux/kubernetes/workers/workers.tf | 15 ++++++++------- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d2cf096a..621d2176 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ Notable changes between versions. ## Latest +#### Google Cloud + +* Add required variable `region` +* Change worker managed instance group to automatically span zones in a region + ## v1.8.2 * Kubernetes v1.8.2 diff --git a/README.md b/README.md index 4c4eaa81..a368a629 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ module "google-cloud-yavin" { source = "git::https://github.com/poseidon/typhoon//google-cloud/container-linux/kubernetes" # Google Cloud + region = "us-central1" zone = "us-central1-c" dns_zone = "example.com" dns_zone_name = "example-zone" diff --git a/docs/google-cloud.md b/docs/google-cloud.md index 12779da5..33db1a92 100644 --- a/docs/google-cloud.md +++ b/docs/google-cloud.md @@ -77,6 +77,7 @@ module "google-cloud-yavin" { source = "git::https://github.com/poseidon/typhoon//google-cloud/container-linux/kubernetes" # Google Cloud + region = "us-central1" zone = "us-central1-c" dns_zone = "example.com" dns_zone_name = "example-zone" @@ -196,6 +197,7 @@ Learn about [version pinning](concepts.md#versioning), maintenance, and [addons] | Name | Description | Example | |:-----|:------------|:--------| | cluster_name | Unique cluster name (prepended to dns_zone) | "yavin" | +| region | Google Cloud region | "us-central1" | | zone | Google Cloud zone | "us-central1-f" | | dns_zone | Google Cloud DNS zone | "google-cloud.example.com" | | dns_zone_name | Google Cloud DNS zone name | "example-zone" | diff --git a/docs/index.md b/docs/index.md index 5f550187..7d880fb8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -46,6 +46,7 @@ module "google-cloud-yavin" { source = "git::https://github.com/poseidon/typhoon//google-cloud/container-linux/kubernetes" # Google Cloud + region = "us-central1" zone = "us-central1-c" dns_zone = "example.com" dns_zone_name = "example-zone" diff --git a/google-cloud/container-linux/kubernetes/cluster.tf b/google-cloud/container-linux/kubernetes/cluster.tf index c47ebef4..d38cc7b3 100644 --- a/google-cloud/container-linux/kubernetes/cluster.tf +++ b/google-cloud/container-linux/kubernetes/cluster.tf @@ -29,8 +29,8 @@ module "workers" { # GCE network = "${google_compute_network.network.name}" + region = "${var.region}" count = "${var.worker_count}" - zone = "${var.zone}" machine_type = "${var.machine_type}" os_image = "${var.os_image}" preemptible = "${var.worker_preemptible}" diff --git a/google-cloud/container-linux/kubernetes/variables.tf b/google-cloud/container-linux/kubernetes/variables.tf index 54ed9dc5..73cb11bc 100644 --- a/google-cloud/container-linux/kubernetes/variables.tf +++ b/google-cloud/container-linux/kubernetes/variables.tf @@ -3,9 +3,14 @@ variable "cluster_name" { description = "Cluster name" } +variable "region" { + type = "string" + description = "Google Cloud Region (e.g. us-central1, see `gcloud compute regions list`)" +} + variable "zone" { type = "string" - description = "Google Cloud zone (e.g. us-central1-f, see `gcloud compute zones list`)" + description = "Google Cloud Zone (e.g. us-central1-f, see `gcloud compute zones list`)" } variable "dns_zone" { diff --git a/google-cloud/container-linux/kubernetes/workers/variables.tf b/google-cloud/container-linux/kubernetes/workers/variables.tf index b3d0bbdd..c706657d 100644 --- a/google-cloud/container-linux/kubernetes/workers/variables.tf +++ b/google-cloud/container-linux/kubernetes/workers/variables.tf @@ -20,9 +20,9 @@ variable "count" { description = "Number of worker compute instances the instance group should manage" } -variable "zone" { +variable "region" { type = "string" - description = "Google zone that compute instances in the group should be created in (e.g. gcloud compute zones list)" + description = "Google Cloud region to create a regional managed group of workers (e.g. us-central1, see `gcloud compute regions list`)." } variable "machine_type" { diff --git a/google-cloud/container-linux/kubernetes/workers/workers.tf b/google-cloud/container-linux/kubernetes/workers/workers.tf index 94882ac1..99b297b1 100644 --- a/google-cloud/container-linux/kubernetes/workers/workers.tf +++ b/google-cloud/container-linux/kubernetes/workers/workers.tf @@ -1,16 +1,17 @@ -# Managed Instance Group -resource "google_compute_instance_group_manager" "workers" { +# Regional managed instance group maintains a homogeneous set of workers that +# span the zones in the region. +resource "google_compute_region_instance_group_manager" "workers" { name = "${var.cluster_name}-worker-group" description = "Compute instance group of ${var.cluster_name} workers" - # Instance name prefix for instances in the group + # instance name prefix for instances in the group base_instance_name = "${var.cluster_name}-worker" instance_template = "${google_compute_instance_template.worker.self_link}" - update_strategy = "RESTART" - zone = "${var.zone}" - target_size = "${var.count}" + region = "${var.region}" - # Target pool instances in the group should be added into + target_size = "${var.count}" + + # target pool to which instances in the group should be added target_pools = [ "${google_compute_target_pool.workers.self_link}", ]