mirror of
https://github.com/puppetmaster/typhoon.git
synced 2024-12-26 18:49:34 +01:00
aaa8e0261a
* Background: A managed instance group of workers is used in backend services for global load balancing (HTTP/HTTPS Ingress) and output for custom global load balancing use cases * Add worker instances to a target pool load balancing TCP/UDP applications (NodePort or proxied). Output as `worker_target_pool` * Health check for workers with a healthy Ingress controller. Forward rules (regional) to target pools don't support different external and internal ports so choosing nodes with Ingress allows proxying as a workaround * A target pool is a logical grouping only. It doesn't add costs to clusters or worker pools
86 lines
2.2 KiB
HCL
86 lines
2.2 KiB
HCL
# Managed instance group of workers
|
|
resource "google_compute_region_instance_group_manager" "workers" {
|
|
name = "${var.name}-worker-group"
|
|
description = "Compute instance group of ${var.name} workers"
|
|
|
|
# instance name prefix for instances in the group
|
|
base_instance_name = "${var.name}-worker"
|
|
instance_template = "${google_compute_instance_template.worker.self_link}"
|
|
region = "${var.region}"
|
|
|
|
target_size = "${var.count}"
|
|
target_pools = ["${google_compute_target_pool.workers.self_link}"]
|
|
|
|
named_port {
|
|
name = "http"
|
|
port = "80"
|
|
}
|
|
|
|
named_port {
|
|
name = "https"
|
|
port = "443"
|
|
}
|
|
}
|
|
|
|
# Worker instance template
|
|
resource "google_compute_instance_template" "worker" {
|
|
name_prefix = "${var.name}-worker-"
|
|
description = "Worker Instance template"
|
|
machine_type = "${var.machine_type}"
|
|
|
|
metadata = {
|
|
user-data = "${data.ct_config.worker-ignition.rendered}"
|
|
}
|
|
|
|
scheduling {
|
|
automatic_restart = "${var.preemptible ? false : true}"
|
|
preemptible = "${var.preemptible}"
|
|
}
|
|
|
|
disk {
|
|
auto_delete = true
|
|
boot = true
|
|
source_image = "${var.os_image}"
|
|
disk_size_gb = "${var.disk_size}"
|
|
}
|
|
|
|
network_interface {
|
|
network = "${var.network}"
|
|
|
|
# Ephemeral external IP
|
|
access_config = {}
|
|
}
|
|
|
|
can_ip_forward = true
|
|
tags = ["worker", "${var.cluster_name}-worker", "${var.name}-worker"]
|
|
|
|
guest_accelerator {
|
|
count = "${var.accelerator_count}"
|
|
type = "${var.accelerator_type}"
|
|
}
|
|
|
|
lifecycle {
|
|
# To update an Instance Template, Terraform should replace the existing resource
|
|
create_before_destroy = true
|
|
}
|
|
}
|
|
|
|
# Worker Ignition config
|
|
data "ct_config" "worker-ignition" {
|
|
content = "${data.template_file.worker-config.rendered}"
|
|
pretty_print = false
|
|
snippets = ["${var.clc_snippets}"]
|
|
}
|
|
|
|
# Worker Container Linux config
|
|
data "template_file" "worker-config" {
|
|
template = "${file("${path.module}/cl/worker.yaml.tmpl")}"
|
|
|
|
vars = {
|
|
kubeconfig = "${indent(10, var.kubeconfig)}"
|
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
|
cluster_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
|
}
|
|
}
|