Make every important setting of the k8s-cluster configurable
This change makes all the settings configurable. The only part which still lacks some flexibility is the location, though I really don't need to run a k8s-cluster over multiple datacenters and regions! - At least right now ;-)
This commit is contained in:
89
main.tf
89
main.tf
@@ -5,19 +5,23 @@ resource "hcloud_ssh_key" "this" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_primary_ip" "k8s_ipv4" {
|
resource "hcloud_primary_ip" "k8s_ipv4" {
|
||||||
name = "k8s_primary_ipv4"
|
count = var.k8s_server_count < 1 ? 1 : var.k8s_server_count
|
||||||
datacenter = "fsn1-dc14"
|
|
||||||
|
name = "k8s_primary_ipv4_${count.index}"
|
||||||
|
datacenter = var.k8s_ip_datacenter
|
||||||
type = "ipv4"
|
type = "ipv4"
|
||||||
assignee_type = "server"
|
assignee_type = "server"
|
||||||
auto_delete = false # change to true and apply before deleting!
|
auto_delete = !var.k8s_test_installation
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_primary_ip" "k8s_ipv6" {
|
resource "hcloud_primary_ip" "k8s_ipv6" {
|
||||||
name = "k8s_primary_ipv6"
|
count = var.k8s_server_count < 1 ? 1 : var.k8s_server_count
|
||||||
datacenter = "fsn1-dc14"
|
|
||||||
|
name = "k8s_primary_ipv6_${count.index}"
|
||||||
|
datacenter = var.k8s_ip_datacenter
|
||||||
type = "ipv6"
|
type = "ipv6"
|
||||||
assignee_type = "server"
|
assignee_type = "server"
|
||||||
auto_delete = false # change to true and apply before deleting!
|
auto_delete = !var.k8s_test_installation
|
||||||
}
|
}
|
||||||
|
|
||||||
data "external" "my_ip" {
|
data "external" "my_ip" {
|
||||||
@@ -33,17 +37,16 @@ module "k8s" {
|
|||||||
|
|
||||||
name = "cluster1"
|
name = "cluster1"
|
||||||
ssh_keys = [for o in hcloud_ssh_key.this : o.id]
|
ssh_keys = [for o in hcloud_ssh_key.this : o.id]
|
||||||
# Ensure a odd number of definitions, since only that make any sense
|
servers = [for n in range(var.k8s_server_count) : {
|
||||||
servers = [{
|
ipv4_id = hcloud_primary_ip.k8s_ipv4[n].id
|
||||||
ipv4_id = hcloud_primary_ip.k8s_ipv4.id
|
ipv6_id = hcloud_primary_ip.k8s_ipv6[n].id
|
||||||
ipv6_id = hcloud_primary_ip.k8s_ipv6.id
|
type = var.k8s_server_type
|
||||||
type = "cax11"
|
location = var.k8s_location
|
||||||
location = "fsn1"
|
|
||||||
}]
|
}]
|
||||||
agents = [{
|
agents = [{
|
||||||
type = "cax11"
|
type = var.k8s_agent_type
|
||||||
location = "fsn1"
|
location = var.k8s_location
|
||||||
count = 1
|
count = var.k8s_agent_count
|
||||||
}]
|
}]
|
||||||
kubernetes_exposed_ips = var.expose_kubernetes_and_ssh_ports ? values(data.external.my_ip.result) : []
|
kubernetes_exposed_ips = var.expose_kubernetes_and_ssh_ports ? values(data.external.my_ip.result) : []
|
||||||
ssh_exposed_ips = var.expose_kubernetes_and_ssh_ports ? values(data.external.my_ip.result) : []
|
ssh_exposed_ips = var.expose_kubernetes_and_ssh_ports ? values(data.external.my_ip.result) : []
|
||||||
@@ -71,19 +74,19 @@ locals {
|
|||||||
"goperte.de" = {
|
"goperte.de" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nehrke.info" = {
|
"nehrke.info" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "@", ttl = 86400, type = "MX", value = "1 smtp.google.com." },
|
{ name = "@", ttl = 86400, type = "MX", value = "1 smtp.google.com." },
|
||||||
{ name = "@", ttl = 86400, type = "TXT", value = "v=spf1 include:_spf.google.com a mx ~all" },
|
{ name = "@", ttl = 86400, type = "TXT", value = "v=spf1 include:_spf.google.com a mx ~all" },
|
||||||
{ name = "_dmarc", ttl = 86400, type = "TXT", value = "v=DMARC1; p=none;" },
|
{ name = "_dmarc", ttl = 86400, type = "TXT", value = "v=DMARC1; p=none;" },
|
||||||
@@ -93,10 +96,10 @@ locals {
|
|||||||
"sozpaedil.net" = {
|
"sozpaedil.net" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "@", ttl = 86400, type = "MX", value = "1 smtp.google.com." },
|
{ name = "@", ttl = 86400, type = "MX", value = "1 smtp.google.com." },
|
||||||
{ name = "@", ttl = 86400, type = "TXT", value = "v=spf1 include:_spf.google.com a mx ~all" },
|
{ name = "@", ttl = 86400, type = "TXT", value = "v=spf1 include:_spf.google.com a mx ~all" },
|
||||||
{ name = "_dmarc", ttl = 86400, type = "TXT", value = "v=DMARC1; p=none;" },
|
{ name = "_dmarc", ttl = 86400, type = "TXT", value = "v=DMARC1; p=none;" },
|
||||||
@@ -106,37 +109,37 @@ locals {
|
|||||||
"tovot.de" = {
|
"tovot.de" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"tovot.net" = {
|
"tovot.net" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"tovot.org" = {
|
"tovot.org" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"xn--alleingnger-r8a.de" = {
|
"xn--alleingnger-r8a.de" = {
|
||||||
zone_ttl = 900
|
zone_ttl = 900
|
||||||
records = [
|
records = [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4.ip_address },
|
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
||||||
{ name = "@", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
{ name = "*", type = "AAAA", value = hcloud_primary_ip.k8s_ipv6.ip_address },
|
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
47
variables.tf
47
variables.tf
@@ -25,3 +25,50 @@ variable "ssh_keys" {
|
|||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "k8s_test_installation" {
|
||||||
|
default = false
|
||||||
|
description = <<EOF
|
||||||
|
When this is set to true we configure primary-ips to not be deleted automatically!
|
||||||
|
This allows us to reuse the same IP for multiple create/destroy cycles.
|
||||||
|
As soon as the test-phase is over this should be false.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Right now this only supports 1 location, but that's okay for me!
|
||||||
|
variable "k8s_location" {
|
||||||
|
type = string
|
||||||
|
description = <<EOF
|
||||||
|
This is the location where I host the k8s-cluster.
|
||||||
|
An overview of possible locations can be found at: https://docs.hetzner.com/cloud/general/locations/
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "k8s_ip_datacenter" {
|
||||||
|
type = string
|
||||||
|
description = <<EOF
|
||||||
|
This is the datacenter where the public IPs of the k8s-cluster belong to.
|
||||||
|
An overview of possible locations can be found at: https://docs.hetzner.com/cloud/general/locations/
|
||||||
|
Note, that the k8s_ip_datacenter has to match the k8s_location!
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "k8s_server_count" {
|
||||||
|
type = number
|
||||||
|
default = 3
|
||||||
|
description = "Number of k8s-server nodes. This should always be an odd number."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "k8s_server_type" {
|
||||||
|
type = string
|
||||||
|
default = "cax11"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "k8s_agent_count" {
|
||||||
|
type = number
|
||||||
|
default = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "k8s_agent_type" {
|
||||||
|
type = string
|
||||||
|
default = "cax11"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user