2018-04-15 09:50:43 +02:00
|
|
|
# TCP Proxy load balancer DNS record
|
|
|
|
resource "google_dns_record_set" "apiserver" {
|
2017-08-13 22:02:52 +02:00
|
|
|
# DNS Zone name where record should be created
|
2019-05-28 06:14:25 +02:00
|
|
|
managed_zone = var.dns_zone_name
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2017-08-13 22:02:52 +02:00
|
|
|
# DNS record
|
2019-05-28 06:14:25 +02:00
|
|
|
name = format("%s.%s.", var.cluster_name, var.dns_zone)
|
2017-06-27 06:55:39 +02:00
|
|
|
type = "A"
|
|
|
|
ttl = 300
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# IPv4 address of apiserver TCP Proxy load balancer
|
2019-05-28 06:14:25 +02:00
|
|
|
rrdatas = [google_compute_global_address.apiserver-ipv4.address]
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# Static IPv4 address for the TCP Proxy Load Balancer
|
|
|
|
resource "google_compute_global_address" "apiserver-ipv4" {
|
2018-05-02 06:41:22 +02:00
|
|
|
name = "${var.cluster_name}-apiserver-ip"
|
2018-04-15 09:50:43 +02:00
|
|
|
ip_version = "IPV4"
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# Forward IPv4 TCP traffic to the TCP proxy load balancer
|
|
|
|
resource "google_compute_global_forwarding_rule" "apiserver" {
|
2018-05-02 06:41:22 +02:00
|
|
|
name = "${var.cluster_name}-apiserver"
|
2019-05-28 06:14:25 +02:00
|
|
|
ip_address = google_compute_global_address.apiserver-ipv4.address
|
2018-04-15 09:50:43 +02:00
|
|
|
ip_protocol = "TCP"
|
2018-05-02 06:41:22 +02:00
|
|
|
port_range = "443"
|
2019-05-28 06:14:25 +02:00
|
|
|
target = google_compute_target_tcp_proxy.apiserver.self_link
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# Global TCP Proxy Load Balancer for apiservers
|
|
|
|
resource "google_compute_target_tcp_proxy" "apiserver" {
|
2018-05-02 06:41:22 +02:00
|
|
|
name = "${var.cluster_name}-apiserver"
|
|
|
|
description = "Distribute TCP load across ${var.cluster_name} controllers"
|
2019-05-28 06:14:25 +02:00
|
|
|
backend_service = google_compute_backend_service.apiserver.self_link
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
2017-11-05 20:01:50 +01:00
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# Global backend service backed by unmanaged instance groups
|
|
|
|
resource "google_compute_backend_service" "apiserver" {
|
2018-05-02 06:41:22 +02:00
|
|
|
name = "${var.cluster_name}-apiserver"
|
2018-04-15 09:50:43 +02:00
|
|
|
description = "${var.cluster_name} apiserver service"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-05-02 06:41:22 +02:00
|
|
|
protocol = "TCP"
|
|
|
|
port_name = "apiserver"
|
2017-06-27 06:55:39 +02:00
|
|
|
session_affinity = "NONE"
|
2018-12-15 23:20:53 +01:00
|
|
|
timeout_sec = "300"
|
2018-04-15 09:50:43 +02:00
|
|
|
|
|
|
|
# controller(s) spread across zonal instance groups
|
2019-07-06 04:21:05 +02:00
|
|
|
dynamic "backend" {
|
|
|
|
for_each = google_compute_instance_group.controllers
|
|
|
|
content {
|
|
|
|
group = backend.value.self_link
|
|
|
|
}
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 06:14:25 +02:00
|
|
|
health_checks = [google_compute_health_check.apiserver.self_link]
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Instance group of heterogeneous (unmanged) controller instances
|
|
|
|
resource "google_compute_instance_group" "controllers" {
|
2019-07-21 01:51:29 +02:00
|
|
|
count = min(var.controller_count, length(local.zones))
|
2018-04-15 09:50:43 +02:00
|
|
|
|
2019-07-06 04:21:05 +02:00
|
|
|
name = format("%s-controllers-%s", var.cluster_name, element(local.zones, count.index))
|
2019-05-28 06:14:25 +02:00
|
|
|
zone = element(local.zones, count.index)
|
2018-04-15 09:50:43 +02:00
|
|
|
|
|
|
|
named_port {
|
|
|
|
name = "apiserver"
|
2019-07-06 22:11:37 +02:00
|
|
|
port = "6443"
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# add instances in the zone into the instance group
|
2019-05-28 06:14:25 +02:00
|
|
|
instances = matchkeys(
|
|
|
|
google_compute_instance.controllers.*.self_link,
|
|
|
|
google_compute_instance.controllers.*.zone,
|
|
|
|
[element(local.zones, count.index)],
|
|
|
|
)
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
# TCP health check for apiserver
|
|
|
|
resource "google_compute_health_check" "apiserver" {
|
2018-05-02 06:41:22 +02:00
|
|
|
name = "${var.cluster_name}-apiserver-tcp-health"
|
2018-04-15 09:50:43 +02:00
|
|
|
description = "TCP health check for kube-apiserver"
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-05-02 06:41:22 +02:00
|
|
|
timeout_sec = 5
|
2017-06-27 06:55:39 +02:00
|
|
|
check_interval_sec = 5
|
|
|
|
|
2018-05-02 06:41:22 +02:00
|
|
|
healthy_threshold = 1
|
2018-04-15 09:50:43 +02:00
|
|
|
unhealthy_threshold = 3
|
2017-06-27 06:55:39 +02:00
|
|
|
|
2018-04-15 09:50:43 +02:00
|
|
|
tcp_health_check {
|
2019-07-06 22:11:37 +02:00
|
|
|
port = "6443"
|
2018-04-15 09:50:43 +02:00
|
|
|
}
|
2017-06-27 06:55:39 +02:00
|
|
|
}
|
2019-05-28 06:14:25 +02:00
|
|
|
|