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
|
2018-08-20 03:48:22 +02:00
|
|
|
# coreos-stable -> Container Linux Stable
|
2020-03-11 07:55:23 +01:00
|
|
|
# flatcar-stable -> Flatcar Linux Stable
|
|
|
|
flavor = split("-", var.os_image)[0]
|
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
|
|
|
|
custom_data = base64encode(data.ct_config.controller-ignitions.*.rendered[count.index])
|
|
|
|
|
|
|
|
# storage
|
|
|
|
os_disk {
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
|
|
caching = "None"
|
|
|
|
disk_size_gb = var.disk_size
|
|
|
|
storage_account_type = "Premium_LRS"
|
|
|
|
}
|
|
|
|
|
|
|
|
source_image_reference {
|
2020-03-11 07:55:23 +01:00
|
|
|
publisher = local.flavor == "flatcar" ? "Kinvolk" : "CoreOS"
|
|
|
|
offer = local.flavor == "flatcar" ? "flatcar-container-linux" : "CoreOS"
|
2019-05-28 06:43:08 +02:00
|
|
|
sku = local.channel
|
2018-08-20 03:48:22 +02:00
|
|
|
version = "latest"
|
|
|
|
}
|
|
|
|
|
2020-03-11 07:55:23 +01:00
|
|
|
# Gross hack just for Flatcar Linux
|
|
|
|
dynamic "plan" {
|
|
|
|
for_each = local.flavor == "flatcar" ? [1] : []
|
|
|
|
|
|
|
|
content {
|
|
|
|
name = local.channel
|
|
|
|
publisher = "kinvolk"
|
|
|
|
product = "flatcar-container-linux"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Controller Ignition configs
|
|
|
|
data "ct_config" "controller-ignitions" {
|
2019-12-28 21:07:10 +01:00
|
|
|
count = var.controller_count
|
|
|
|
content = data.template_file.controller-configs.*.rendered[count.index]
|
2018-08-20 03:48:22 +02:00
|
|
|
pretty_print = false
|
2020-03-29 20:46:22 +02:00
|
|
|
snippets = var.controller_snippets
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Controller Container Linux configs
|
|
|
|
data "template_file" "controller-configs" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2019-12-28 21:07:10 +01:00
|
|
|
template = file("${path.module}/cl/controller.yaml")
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
vars = {
|
|
|
|
# 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,...
|
2019-05-28 06:43:08 +02:00
|
|
|
etcd_initial_cluster = join(",", data.template_file.etcds.*.rendered)
|
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
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data "template_file" "etcds" {
|
2019-05-28 06:43:08 +02:00
|
|
|
count = var.controller_count
|
2018-08-20 03:48:22 +02:00
|
|
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
|
|
|
|
2019-03-12 09:19:54 +01:00
|
|
|
vars = {
|
2019-05-28 06:43:08 +02:00
|
|
|
index = count.index
|
|
|
|
cluster_name = var.cluster_name
|
|
|
|
dns_zone = var.dns_zone
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|