2019-03-30 23:12:55 +01:00
|
|
|
# Managed instance group of workers
|
2017-11-04 18:57:12 +01:00
|
|
|
resource "google_compute_region_instance_group_manager" "workers" {
|
2022-08-14 21:12:55 +02:00
|
|
|
name = "${var.name}-worker"
|
2018-03-04 01:21:38 +01:00
|
|
|
description = "Compute instance group of ${var.name} workers"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-11-04 18:57:12 +01:00
|
|
|
# instance name prefix for instances in the group
|
2018-03-04 01:21:38 +01:00
|
|
|
base_instance_name = "${var.name}-worker"
|
2019-05-28 06:14:25 +02:00
|
|
|
region = var.region
|
2019-11-14 02:31:11 +01:00
|
|
|
version {
|
2019-11-14 08:44:02 +01:00
|
|
|
name = "default"
|
2024-08-28 06:30:55 +02:00
|
|
|
instance_template = google_compute_region_instance_template.worker.self_link
|
2019-11-14 02:31:11 +01:00
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2022-08-14 21:12:55 +02:00
|
|
|
# Roll out MIG instance template changes by replacing instances.
|
|
|
|
# - Surge to create new instances, then delete old instances.
|
|
|
|
# - Replace ensures new Ignition is picked up
|
|
|
|
update_policy {
|
|
|
|
type = "PROACTIVE"
|
|
|
|
max_surge_fixed = 3
|
|
|
|
max_unavailable_fixed = 0
|
|
|
|
minimal_action = "REPLACE"
|
|
|
|
}
|
|
|
|
|
2019-05-28 06:14:25 +02:00
|
|
|
target_size = var.worker_count
|
|
|
|
target_pools = [google_compute_target_pool.workers.self_link]
|
2017-11-04 18:57:12 +01:00
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
named_port {
|
|
|
|
name = "http"
|
|
|
|
port = "80"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
named_port {
|
|
|
|
name = "https"
|
|
|
|
port = "443"
|
|
|
|
}
|
2022-08-14 21:12:55 +02:00
|
|
|
|
|
|
|
auto_healing_policies {
|
|
|
|
health_check = google_compute_health_check.worker.id
|
2022-08-18 05:50:52 +02:00
|
|
|
initial_delay_sec = 300
|
2022-08-14 21:12:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Health check for worker Kubelet
|
|
|
|
resource "google_compute_health_check" "worker" {
|
2022-08-18 05:50:52 +02:00
|
|
|
name = "${var.name}-worker-health"
|
|
|
|
description = "Health check for worker node"
|
2022-08-14 21:12:55 +02:00
|
|
|
|
|
|
|
timeout_sec = 20
|
|
|
|
check_interval_sec = 30
|
|
|
|
|
|
|
|
healthy_threshold = 1
|
|
|
|
unhealthy_threshold = 6
|
|
|
|
|
2022-08-18 05:50:52 +02:00
|
|
|
http_health_check {
|
|
|
|
port = "10256"
|
|
|
|
request_path = "/healthz"
|
2022-08-14 21:12:55 +02:00
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 08:21:53 +02:00
|
|
|
# Worker instance template
|
2024-08-28 06:30:55 +02:00
|
|
|
resource "google_compute_region_instance_template" "worker" {
|
2019-03-28 03:45:10 +01:00
|
|
|
name_prefix = "${var.name}-worker-"
|
|
|
|
description = "Worker Instance template"
|
2019-05-28 06:14:25 +02:00
|
|
|
machine_type = var.machine_type
|
2024-10-09 06:25:06 +02:00
|
|
|
region = var.region
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
metadata = {
|
2022-08-03 03:15:03 +02:00
|
|
|
user-data = data.ct_config.worker.rendered
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
scheduling {
|
2022-08-14 21:12:55 +02:00
|
|
|
provisioning_model = var.preemptible ? "SPOT" : "STANDARD"
|
|
|
|
preemptible = var.preemptible
|
|
|
|
automatic_restart = var.preemptible ? false : true
|
|
|
|
# Spot instances with termination action DELETE cannot be used with MIGs
|
|
|
|
instance_termination_action = var.preemptible ? "STOP" : null
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
|
|
|
auto_delete = true
|
|
|
|
boot = true
|
2022-01-29 05:59:15 +01:00
|
|
|
source_image = data.google_compute_image.flatcar-linux.self_link
|
2019-05-28 06:14:25 +02:00
|
|
|
disk_size_gb = var.disk_size
|
2024-09-20 23:31:17 +02:00
|
|
|
disk_type = var.disk_type
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
network_interface {
|
2019-05-28 06:14:25 +02:00
|
|
|
network = var.network
|
2017-06-27 06:55:39 +02:00
|
|
|
# Ephemeral external IP
|
2022-08-14 21:12:55 +02:00
|
|
|
access_config {}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
can_ip_forward = true
|
2018-02-20 17:36:21 +01:00
|
|
|
tags = ["worker", "${var.cluster_name}-worker", "${var.name}-worker"]
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-03-03 02:26:51 +01:00
|
|
|
guest_accelerator {
|
2019-05-28 06:14:25 +02:00
|
|
|
count = var.accelerator_count
|
|
|
|
type = var.accelerator_type
|
2018-03-03 02:26:51 +01:00
|
|
|
}
|
|
|
|
|
2017-06-27 06:55:39 +02:00
|
|
|
lifecycle {
|
2022-08-14 21:12:55 +02:00
|
|
|
ignore_changes = [
|
|
|
|
disk[0].source_image
|
|
|
|
]
|
2017-06-27 06:55:39 +02:00
|
|
|
# To update an Instance Template, Terraform should replace the existing resource
|
|
|
|
create_before_destroy = true
|
|
|
|
}
|
|
|
|
}
|
2018-05-07 08:21:53 +02:00
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
# Flatcar Linux worker
|
|
|
|
data "ct_config" "worker" {
|
2022-08-03 03:12:37 +02:00
|
|
|
content = templatefile("${path.module}/butane/worker.yaml", {
|
2019-05-28 06:14:25 +02:00
|
|
|
kubeconfig = indent(10, var.kubeconfig)
|
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
2019-09-28 23:59:24 +02:00
|
|
|
node_labels = join(",", var.node_labels)
|
2021-04-11 21:08:56 +02:00
|
|
|
node_taints = join(",", var.node_taints)
|
2022-08-03 03:15:03 +02:00
|
|
|
})
|
|
|
|
strict = true
|
|
|
|
snippets = var.snippets
|
2018-05-07 08:21:53 +02:00
|
|
|
}
|