diff --git a/contrib/terraform/gcp/README.md b/contrib/terraform/gcp/README.md index b036c5b71bd87c172d0a101c6d2bfc16146b3d07..a7f23b35485831ff4af5c82b7ab78c56f4e3391a 100644 --- a/contrib/terraform/gcp/README.md +++ b/contrib/terraform/gcp/README.md @@ -80,8 +80,12 @@ ansible-playbook -i contrib/terraform/gcs/inventory.ini cluster.yml -b -v * `prefix`: Prefix to use for all resources, required to be unique for all clusters in the same project *(Defaults to `default`)* * `master_sa_email`: Service account email to use for the master nodes *(Defaults to `""`, auto generate one)* * `master_sa_scopes`: Service account email to use for the master nodes *(Defaults to `["https://www.googleapis.com/auth/cloud-platform"]`)* +* `master_preemptible`: Enable [preemptible](https://cloud.google.com/compute/docs/instances/preemptible) + for the master nodes *(Defaults to `false`)* * `worker_sa_email`: Service account email to use for the worker nodes *(Defaults to `""`, auto generate one)* * `worker_sa_scopes`: Service account email to use for the worker nodes *(Defaults to `["https://www.googleapis.com/auth/cloud-platform"]`)* +* `worker_preemptible`: Enable [preemptible](https://cloud.google.com/compute/docs/instances/preemptible) + for the worker nodes *(Defaults to `false`)* An example variables file can be found `tfvars.json` diff --git a/contrib/terraform/gcp/main.tf b/contrib/terraform/gcp/main.tf index 0367d49b6ed4e2555b049cd6343d0f6860747654..ce221d0c12fd2b2367c950dde0557b11736065a0 100644 --- a/contrib/terraform/gcp/main.tf +++ b/contrib/terraform/gcp/main.tf @@ -21,10 +21,12 @@ module "kubernetes" { machines = var.machines ssh_pub_key = var.ssh_pub_key - master_sa_email = var.master_sa_email - master_sa_scopes = var.master_sa_scopes - worker_sa_email = var.worker_sa_email - worker_sa_scopes = var.worker_sa_scopes + master_sa_email = var.master_sa_email + master_sa_scopes = var.master_sa_scopes + master_preemptible = var.master_preemptible + worker_sa_email = var.worker_sa_email + worker_sa_scopes = var.worker_sa_scopes + worker_preemptible = var.worker_preemptible ssh_whitelist = var.ssh_whitelist api_server_whitelist = var.api_server_whitelist diff --git a/contrib/terraform/gcp/modules/kubernetes-cluster/main.tf b/contrib/terraform/gcp/modules/kubernetes-cluster/main.tf index 9e0d3263760b89349dc033aa5e22ff0d20a6e8bf..a9cbacbaa9278b1e5586881a6e80eca0f70ae03b 100644 --- a/contrib/terraform/gcp/modules/kubernetes-cluster/main.tf +++ b/contrib/terraform/gcp/modules/kubernetes-cluster/main.tf @@ -231,6 +231,11 @@ resource "google_compute_instance" "master" { lifecycle { ignore_changes = [attached_disk] } + + scheduling { + preemptible = var.master_preemptible + automatic_restart = !var.master_preemptible + } } resource "google_compute_forwarding_rule" "master_lb" { @@ -328,6 +333,11 @@ resource "google_compute_instance" "worker" { lifecycle { ignore_changes = [attached_disk] } + + scheduling { + preemptible = var.worker_preemptible + automatic_restart = !var.worker_preemptible + } } resource "google_compute_address" "worker_lb" { diff --git a/contrib/terraform/gcp/modules/kubernetes-cluster/variables.tf b/contrib/terraform/gcp/modules/kubernetes-cluster/variables.tf index d6632ac4bc2326907cc373ddc9e806027bbc3cd1..5fddca26d03f27c0ecf367cfcd5c013eff08ac25 100644 --- a/contrib/terraform/gcp/modules/kubernetes-cluster/variables.tf +++ b/contrib/terraform/gcp/modules/kubernetes-cluster/variables.tf @@ -27,6 +27,10 @@ variable "master_sa_scopes" { type = list(string) } +variable "master_preemptible" { + type = bool +} + variable "worker_sa_email" { type = string } @@ -35,6 +39,10 @@ variable "worker_sa_scopes" { type = list(string) } +variable "worker_preemptible" { + type = bool +} + variable "ssh_pub_key" {} variable "ssh_whitelist" { diff --git a/contrib/terraform/gcp/variables.tf b/contrib/terraform/gcp/variables.tf index 9850e61c5147fcadf6ec28d7d2bfa868b5d9338e..207a803211651c1b7603d34043eb70136b903c39 100644 --- a/contrib/terraform/gcp/variables.tf +++ b/contrib/terraform/gcp/variables.tf @@ -44,6 +44,11 @@ variable "master_sa_scopes" { default = ["https://www.googleapis.com/auth/cloud-platform"] } +variable "master_preemptible" { + type = bool + default = false +} + variable "worker_sa_email" { type = string default = "" @@ -54,6 +59,11 @@ variable "worker_sa_scopes" { default = ["https://www.googleapis.com/auth/cloud-platform"] } +variable "worker_preemptible" { + type = bool + default = false +} + variable ssh_pub_key { description = "Path to public SSH key file which is injected into the VMs." type = string