k3s-install ready for testing

This commit is contained in:
Karim Naufal
2022-02-16 03:18:40 +01:00
parent 1f0c825b23
commit fec695086a
9 changed files with 205 additions and 66 deletions

View File

@@ -31,15 +31,13 @@ resource "hcloud_server" "first_control_plane" {
# Install MicroOS
provisioner "remote-exec" {
inline = local.MicroOS_install_commands
inline = local.microOS_install_commands
}
# Issue a reboot command
# Issue a reboot command and wait for the node to reboot
provisioner "local-exec" {
command = "ssh ${local.ssh_args} root@${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3"
}
# Wait for MicroOS to reboot and be ready
provisioner "local-exec" {
command = <<-EOT
until ssh ${local.ssh_args} -o ConnectTimeout=2 root@${self.ipv4_address} true 2> /dev/null
@@ -63,27 +61,42 @@ resource "hcloud_server" "first_control_plane" {
advertise-address = local.first_control_plane_network_ip
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"] : []
})
destination = "/etc/rancher/k3s/config.yaml"
destination = "/tmp/config.yaml"
}
/* # Run the first control plane
# Install k3s server
provisioner "remote-exec" {
inline = local.install_k3s_server
}
# Issue a reboot command and wait for the node to reboot
provisioner "local-exec" {
command = "ssh ${local.ssh_args} root@${self.ipv4_address} '(sleep 2; reboot)&'; sleep 3"
}
provisioner "local-exec" {
command = <<-EOT
until ssh ${local.ssh_args} -o ConnectTimeout=2 root@${self.ipv4_address} true 2> /dev/null
do
echo "Waiting for MicroOS to reboot and become available..."
sleep 2
done
EOT
}
# Upon reboot verify that the k3s server is starts, and wait for k3s to be ready to receive commands
provisioner "remote-exec" {
inline = [
# set the hostname in a persistent fashion
"hostnamectl set-hostname ${self.name}",
# 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 a directory for our post-installation kustomizations
# prepare the post_install directory
"mkdir -p /tmp/post_install",
# then we initiate the cluster
"systemctl enable k3s-server",
# wait for k3s to get ready
# wait for k3s to become ready
<<-EOT
timeout 120 bash <<EOF
until systemctl status k3s-server > /dev/null; do
systemctl start k3s-server
echo "Initiating the cluster..."
until systemctl status k3s > /dev/null; do
echo "Waiting for the k3s server to start..."
sleep 1
done
until [ -e /etc/rancher/k3s/k3s.yaml ]; do
@@ -108,7 +121,8 @@ resource "hcloud_server" "first_control_plane" {
"https://github.com/hetznercloud/hcloud-cloud-controller-manager/releases/download/${local.ccm_version}/ccm-networks.yaml",
"https://raw.githubusercontent.com/hetznercloud/csi-driver/${local.csi_version}/deploy/kubernetes/hcloud-csi.yml",
"https://github.com/weaveworks/kured/releases/download/${local.kured_version}/kured-${local.kured_version}-dockerhub.yaml",
"./traefik.yaml"
"https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml",
"./traefik.yaml",
]
patchesStrategicMerge = [
file("${path.module}/patches/kured.yaml"),
@@ -132,9 +146,20 @@ resource "hcloud_server" "first_control_plane" {
destination = "/tmp/post_install/traefik.yaml"
}
# Upload the system upgrade controller plans config
provisioner "file" {
content = templatefile(
"${path.module}/templates/plans.yaml.tpl",
{
channel = var.k3s_upgrade_channel
})
destination = "/tmp/post_install/plans.yaml"
}
# Deploy secrets, logging is automatically disabled due to sensitive variables
provisioner "remote-exec" {
inline = [
"set -ex",
"kubectl -n kube-system create secret generic hcloud --from-literal=token=${var.hcloud_token} --from-literal=network=${hcloud_network.k3s.name}",
"kubectl -n kube-system create secret generic hcloud-csi --from-literal=token=${var.hcloud_token}",
]
@@ -143,6 +168,7 @@ resource "hcloud_server" "first_control_plane" {
# Deploy our post-installation kustomization
provisioner "remote-exec" {
inline = [
"set -ex",
# This ugly hack is here, because terraform serializes the
# embedded yaml files with "- |2", when there is more than
# one yamldocument in the embedded file. Kustomize does not understand
@@ -153,8 +179,10 @@ 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",
"kubectl apply -f /tmp/post_install/plans.yaml"
]
} */
}
network {
network_id = hcloud_network.k3s.id