Fix writing microk8s config

This commit is contained in:
2023-11-04 14:05:05 +01:00
parent c64313eeda
commit 1336405f13
4 changed files with 14 additions and 8 deletions
@@ -65,10 +65,10 @@ resource "hcloud_server" "manager" {
terraform_public_ssh_key : var.terraform_public_ssh_key,
microk8s_channel : var.microk8s_channel,
admin_user : var.admin_user,
microk8s_config : templatefile("${path.module}/templates/microk8s-config.tftpl", {
microk8s_config : base64encode(templatefile("${path.module}/templates/microk8s-config.tftpl", {
node_ip : var.private_node_ips[count.index],
api_server_domain : local.kube_api_server_domain
})
}))
})
shutdown_before_deletion = true
@@ -19,6 +19,11 @@ package_upgrade: true
snap:
commands:
- snap install kubectl --classic
write_files:
- owner: root:root
content: "${microk8s_config}"
path: /var/snap/microk8s/common/.microk8s.yaml
encoding: base64
runcmd:
- printf "[sshd]\nenabled = true\nbanaction = iptables-multiport" > /etc/fail2ban/jail.local
- systemctl enable fail2ban
@@ -41,8 +46,6 @@ runcmd:
- sed -i '$a AllowUsers ${admin_user} terraform' /etc/ssh/sshd_config
- curl https://packages.hetzner.com/hcloud/deb/hc-utils_0.0.4-1_all.deb -o /tmp/hc-utils_0.0.4-1_all.deb -s
- apt install /tmp/hc-utils_0.0.4-1_all.deb
- mkdir -p /var/snap/microk8s/common/
- echo "${microk8s_config}" > /var/snap/microk8s/common/.microk8s.yaml
- snap install microk8s --channel ${microk8s_channel}
- mkdir -p /home/terraform/.kube
- microk8s kubectl config view --raw > /home/terraform/.kube/config
+2 -2
View File
@@ -54,10 +54,10 @@ resource "hcloud_server" "worker" {
terraform_public_ssh_key : var.terraform_public_ssh_key,
microk8s_channel : var.microk8s_channel,
admin_user : var.admin_user,
microk8s_config : templatefile("${path.module}/templates/microk8s-config.tftpl", {
microk8s_config : base64encode(templatefile("${path.module}/templates/microk8s-config.tftpl", {
node_ip : var.private_worker_node_ips[count.index],
api_server_domain : local.kube_api_server_domain
})
}))
})
shutdown_before_deletion = true
+5 -2
View File
@@ -1,6 +1,9 @@
output "ansible_inventory" {
value = templatefile("${path.module}/templates/inventory.tftpl", {
devops = hcloud_server.server_devops.ipv4_address,
k8s_servers = concat(tolist([hcloud_server.server_k8s_test.ipv4_address]), module.test_cluster.node_ipv6_addresses)
devops = hcloud_server.server_devops.ipv4_address,
k8s_servers = concat(
tolist([hcloud_server.server_k8s_test.ipv4_address]),
# module.test_cluster.node_ipv6_addresses
)
})
}