2018-08-20 03:48:22 +02:00
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
|
|
|
resource "azurerm_dns_a_record" "etcds" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = var.dns_zone_group
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
# DNS Zone name where record should be created
|
2019-05-28 06:43:08 +02:00
|
|
|
zone_name = var.dns_zone
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
# DNS record
|
2019-05-28 06:43:08 +02:00
|
|
|
name = format("%s-etcd%d", var.cluster_name, count.index)
|
2018-08-20 03:48:22 +02:00
|
|
|
ttl = 300
|
|
|
|
|
|
|
|
# private IPv4 address for etcd
|
2019-12-28 21:07:10 +01:00
|
|
|
records = [azurerm_network_interface.controllers.*.private_ip_address[count.index]]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
2020-03-11 07:55:23 +01:00
|
|
|
# Container Linux derivative
|
|
|
|
# flatcar-stable -> Flatcar Linux Stable
|
2019-12-28 21:07:10 +01:00
|
|
|
channel = split("-", var.os_image)[1]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller availability set to spread controllers
|
|
|
|
resource "azurerm_availability_set" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controllers"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
2018-08-20 03:48:22 +02:00
|
|
|
platform_fault_domain_count = 2
|
|
|
|
platform_update_domain_count = 4
|
|
|
|
managed = true
|
|
|
|
}
|
|
|
|
|
|
|
|
# Controller instances
|
2020-03-08 03:40:39 +01:00
|
|
|
resource "azurerm_linux_virtual_machine" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = var.region
|
|
|
|
availability_set_id = azurerm_availability_set.controllers.id
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
size = var.controller_type
|
2022-08-03 03:15:03 +02:00
|
|
|
custom_data = base64encode(data.ct_config.controllers.*.rendered[count.index])
|
2020-03-08 03:40:39 +01:00
|
|
|
|
|
|
|
# storage
|
|
|
|
os_disk {
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
caching = "None"
|
|
|
|
disk_size_gb = var.disk_size
|
|
|
|
storage_account_type = "Premium_LRS"
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:55:32 +02:00
|
|
|
# Flatcar Container Linux
|
2020-05-10 02:37:35 +02:00
|
|
|
source_image_reference {
|
2020-09-25 04:55:32 +02:00
|
|
|
publisher = "Kinvolk"
|
|
|
|
offer = "flatcar-container-linux-free"
|
2020-05-10 02:37:35 +02:00
|
|
|
sku = local.channel
|
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
|
2020-09-25 04:55:32 +02:00
|
|
|
plan {
|
|
|
|
name = local.channel
|
|
|
|
publisher = "kinvolk"
|
|
|
|
product = "flatcar-container-linux-free"
|
2020-03-11 07:55:23 +01:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# network
|
2020-03-08 03:40:39 +01:00
|
|
|
network_interface_ids = [
|
|
|
|
azurerm_network_interface.controllers.*.id[count.index]
|
|
|
|
]
|
|
|
|
|
|
|
|
# Azure requires setting admin_ssh_key, though Ignition custom_data handles it too
|
|
|
|
admin_username = "core"
|
|
|
|
admin_ssh_key {
|
|
|
|
username = "core"
|
|
|
|
public_key = var.ssh_authorized_key
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
ignore_changes = [
|
2020-03-08 03:40:39 +01:00
|
|
|
os_disk,
|
|
|
|
custom_data,
|
2018-08-20 03:48:22 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
# Controller public IPv4 addresses
|
|
|
|
resource "azurerm_public_ip" "controllers" {
|
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
|
|
|
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
location = azurerm_resource_group.cluster.location
|
|
|
|
sku = "Standard"
|
|
|
|
allocation_method = "Static"
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Controller NICs with public and private IPv4
|
|
|
|
resource "azurerm_network_interface" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
location = azurerm_resource_group.cluster.location
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "ip0"
|
2019-05-28 06:43:08 +02:00
|
|
|
subnet_id = azurerm_subnet.controller.id
|
2020-03-08 03:40:39 +01:00
|
|
|
private_ip_address_allocation = "Dynamic"
|
|
|
|
# instance public IPv4
|
2019-12-28 21:07:10 +01:00
|
|
|
public_ip_address_id = azurerm_public_ip.controllers.*.id[count.index]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
# Associate controller network interface with controller security group
|
|
|
|
resource "azurerm_network_interface_security_group_association" "controllers" {
|
|
|
|
count = var.controller_count
|
|
|
|
|
|
|
|
network_interface_id = azurerm_network_interface.controllers[count.index].id
|
|
|
|
network_security_group_id = azurerm_network_security_group.controller.id
|
|
|
|
}
|
|
|
|
|
|
|
|
# Associate controller network interface with controller backend address pool
|
2018-10-28 06:46:10 +01:00
|
|
|
resource "azurerm_network_interface_backend_address_pool_association" "controllers" {
|
2019-07-21 19:32:58 +02:00
|
|
|
count = var.controller_count
|
|
|
|
|
|
|
|
network_interface_id = azurerm_network_interface.controllers[count.index].id
|
2018-10-28 06:46:10 +01:00
|
|
|
ip_configuration_name = "ip0"
|
2019-05-28 06:43:08 +02:00
|
|
|
backend_address_pool_id = azurerm_lb_backend_address_pool.controller.id
|
2018-10-28 06:46:10 +01:00
|
|
|
}
|
|
|
|
|
2022-08-03 03:15:03 +02:00
|
|
|
# Flatcar Linux controllers
|
|
|
|
data "ct_config" "controllers" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
2022-08-03 03:15:03 +02:00
|
|
|
content = templatefile("${path.module}/cl/controller.yaml", {
|
2018-08-20 03:48:22 +02:00
|
|
|
# Cannot use cyclic dependencies on controllers or their DNS records
|
|
|
|
etcd_name = "etcd${count.index}"
|
|
|
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
2022-08-03 03:15:03 +02:00
|
|
|
etcd_initial_cluster = join(",", [
|
|
|
|
for i in range(var.controller_count) : "etcd${i}=https://${var.cluster_name}-etcd${i}.${var.dns_zone}:2380"
|
|
|
|
])
|
2019-09-15 01:24:32 +02:00
|
|
|
kubeconfig = indent(10, module.bootstrap.kubeconfig-kubelet)
|
2019-05-28 06:43:08 +02:00
|
|
|
ssh_authorized_key = var.ssh_authorized_key
|
|
|
|
cluster_dns_service_ip = cidrhost(var.service_cidr, 10)
|
|
|
|
cluster_domain_suffix = var.cluster_domain_suffix
|
2022-08-03 03:15:03 +02:00
|
|
|
})
|
|
|
|
strict = true
|
|
|
|
snippets = var.controller_snippets
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|