From d9201326948d8d0b0e3071af66b60349be773705 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Wed, 16 Feb 2022 04:24:20 +0100 Subject: [PATCH] k3s install method ok --- agents.tf | 21 ++++----------------- locals.tf | 16 ++++++++++++++-- main.tf | 4 ++-- master.tf | 9 +++++---- servers.tf | 4 ++-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/agents.tf b/agents.tf index 31a26c3..c21cdf0 100644 --- a/agents.tf +++ b/agents.tf @@ -54,6 +54,8 @@ resource "hcloud_server" "agents" { provisioner "file" { content = yamlencode({ node-name = self.name + server = "https://${local.first_control_plane_network_ip}:6443" + token = random_password.k3s_token.result kubelet-arg = "cloud-provider=external" flannel-iface = "eth1" node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 257 + count.index) @@ -64,22 +66,7 @@ resource "hcloud_server" "agents" { # Install k3s agent provisioner "remote-exec" { - inline = [ - "set -ex", - # first we disable automatic reboot (after transactional updates), and configure the reboot method as kured - "rebootmgrctl set-strategy off && echo 'REBOOT_METHOD=kured' > /etc/transactional-update.conf", - # prepare the k3s config directory - "mkdir -p /etc/rancher/k3s", - # move the config file into place - "mv /tmp/config.yaml /etc/rancher/k3s/config.yaml", - # install k3s - <<-EOT - INSTALL_K3S_SKIP_START=true \ - K3S_URL=${"https://${local.first_control_plane_network_ip}:6443"} \ - K3S_TOKEN=${random_password.k3s_token.result} \ - curl -sfL https://get.k3s.io | sh - - EOT - ] + inline = local.install_k3s_agent } # Issue a reboot command and wait for the node to reboot @@ -103,7 +90,7 @@ resource "hcloud_server" "agents" { timeout 120 bash < /dev/null; do echo "Waiting for the k3s agent to start..." - sleep 1 + sleep 2 done EOF EOT diff --git a/locals.tf b/locals.tf index 68ac33c..b6085bc 100644 --- a/locals.tf +++ b/locals.tf @@ -43,7 +43,19 @@ locals { "mkdir -p /etc/rancher/k3s", # move the config file into place "mv /tmp/config.yaml /etc/rancher/k3s/config.yaml", - # install k3s - "INSTALL_K3S_SKIP_START=true curl -sfL https://get.k3s.io | sh -", + # install k3s server + "curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_EXEC=server sh -", + ] + + install_k3s_agent = [ + "set -ex", + # first we disable automatic reboot (after transactional updates), and configure the reboot method as kured + "rebootmgrctl set-strategy off && echo 'REBOOT_METHOD=kured' > /etc/transactional-update.conf", + # prepare the k3s config directory + "mkdir -p /etc/rancher/k3s", + # move the config file into place + "mv /tmp/config.yaml /etc/rancher/k3s/config.yaml", + # install k3s server + "curl -sfL https://get.k3s.io | INSTALL_K3S_SKIP_START=true INSTALL_K3S_EXEC=agent sh -", ] } diff --git a/main.tf b/main.tf index ccf919b..230d9d5 100644 --- a/main.tf +++ b/main.tf @@ -153,8 +153,8 @@ resource "hcloud_placement_group" "k3s" { } } -/* data "hcloud_load_balancer" "traefik" { +data "hcloud_load_balancer" "traefik" { name = "traefik" depends_on = [hcloud_server.agents[0]] -} */ +} diff --git a/master.tf b/master.tf index 6eb8991..7aeeda0 100644 --- a/master.tf +++ b/master.tf @@ -97,15 +97,15 @@ resource "hcloud_server" "first_control_plane" { timeout 120 bash < /dev/null; do echo "Waiting for the k3s server to start..." - sleep 1 + sleep 2 done until [ -e /etc/rancher/k3s/k3s.yaml ]; do echo "Waiting for kubectl config..." - sleep 1 + sleep 2 done until [[ "\$(kubectl get --raw='/readyz' 2> /dev/null)" == "ok" ]]; do echo "Waiting for the cluster to become ready..." - sleep 1 + sleep 2 done EOF EOT @@ -179,7 +179,8 @@ resource "hcloud_server" "first_control_plane" { # manifests themselves "sed -i 's/^- |[0-9]\\+$/- |/g' /tmp/post_install/kustomization.yaml", "kubectl apply -k /tmp/post_install", - "echo 'Waiting for the system-upgrade-controller deployment to become available...' && kubectl -n system-upgrade wait --for=condition=available --timeout=300s deployment/system-upgrade-controller", + "echo 'Waiting for the system-upgrade-controller deployment to become available...'", + "kubectl -n system-upgrade wait --for=condition=available --timeout=300s deployment/system-upgrade-controller", "kubectl apply -f /tmp/post_install/plans.yaml" ] } diff --git a/servers.tf b/servers.tf index b3835e9..7092847 100644 --- a/servers.tf +++ b/servers.tf @@ -54,6 +54,7 @@ resource "hcloud_server" "control_planes" { content = yamlencode({ node-name = self.name server = "https://${local.first_control_plane_network_ip}:6443" + token = random_password.k3s_token.result cluster-init = true disable-cloud-controller = true disable = "servicelb, local-storage" @@ -62,7 +63,6 @@ resource "hcloud_server" "control_planes" { node-ip = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) advertise-address = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) tls-san = cidrhost(hcloud_network_subnet.k3s.ip_range, 3 + count.index) - token = random_password.k3s_token.result node-taint = var.allow_scheduling_on_control_plane ? [] : ["node-role.kubernetes.io/master:NoSchedule"] node-label = var.automatically_upgrade_k3s ? ["k3s_upgrade=true"] : [] }) @@ -95,7 +95,7 @@ resource "hcloud_server" "control_planes" { timeout 120 bash < /dev/null; do echo "Waiting for the k3s server to start..." - sleep 1 + sleep 2 done EOF EOT