Browse Source

terraform/gcp: Allow to use preemptible VM instances (#8480)

pull/8494/head
Mathieu Parent 2 years ago
committed by GitHub
parent
commit
3562d3378b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 4 deletions
  1. 4
      contrib/terraform/gcp/README.md
  2. 10
      contrib/terraform/gcp/main.tf
  3. 10
      contrib/terraform/gcp/modules/kubernetes-cluster/main.tf
  4. 8
      contrib/terraform/gcp/modules/kubernetes-cluster/variables.tf
  5. 10
      contrib/terraform/gcp/variables.tf

4
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`

10
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

10
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" {

8
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" {

10
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

Loading…
Cancel
Save