k3s install method ok

This commit is contained in:
Karim Naufal 2022-02-16 04:24:20 +01:00
parent fec695086a
commit d920132694
5 changed files with 27 additions and 27 deletions

View File

@ -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 <<EOF
until systemctl status k3s-agent > /dev/null; do
echo "Waiting for the k3s agent to start..."
sleep 1
sleep 2
done
EOF
EOT

View File

@ -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 -",
]
}

View File

@ -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]]
} */
}

View File

@ -97,15 +97,15 @@ resource "hcloud_server" "first_control_plane" {
timeout 120 bash <<EOF
until systemctl status k3s > /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"
]
}

View File

@ -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 <<EOF
until systemctl status k3s > /dev/null; do
echo "Waiting for the k3s server to start..."
sleep 1
sleep 2
done
EOF
EOT