refactor: replace manual nodes with flatcar auto joined

This commit is contained in:
Peter 2023-01-25 07:31:17 +01:00
parent 141d6690a2
commit 926f9f2e79
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
5 changed files with 19 additions and 82 deletions

View file

@ -1,51 +0,0 @@
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKfHZaI0F5GjAcrM8hjWqwMfULDkAZ2TOIBTQtRocg1F
hostname: ${host}
write_files:
- enconding: ""
content: |-
#!/bin/bash
write_log () {
local message="$1"
logger -t "run-cmd" "$message"
echo "$message"
}
write_log "Getting the service using eth0..."
ETH1=$(connmanctl services | awk '{ print $3 }' | while read -r s1; do connmanctl services $s1 | grep -q "eth1" && echo "$s1"; done)
write_log "eth1 is bound to: $ETH1"
write_log "Setting up manual net config..."
connmanctl config "$ETH1" --ipv4 manual ${node_ip} 255.255.254.0 172.23.2.10
connmanctl config "$ETH1" --domains k8s.local
connmanctl config "$ETH1" --ipv6 off
write_log "Restarting connman..."
service connman restart
write_log "$(connmanctl services $ETH1)"
write_log "Network setup done."
owner: root:root
path: /etc/run-cmd.sh
permissions: '0755'
run_cmd:
- "/etc/run-cmd.sh"
k3os:
data_sources:
- hetzner
- cdrom
modules:
- kvm
- nvme
dns_nameservers:
- 1.1.1.1
- 1.0.0.1
ntp_servers:
- ptbtime1.ptb.de
- ptbtime2.ptb.de
server_url: https://172.23.2.10:6443
password: rancher
token: "${k3s_token}"
labels:
region: ${datacenter}
k3s_args:
- agent
- --node-ip=${node_ip}
- --kubelet-arg=cloud-provider=external

View file

@ -19,7 +19,7 @@ systemd:
KillMode=process KillMode=process
Environment="K3S_URL=https://172.23.2.10:6443" Environment="K3S_URL=https://172.23.2.10:6443"
Environment="K3S_TOKEN=${k3s_token}" Environment="K3S_TOKEN=${k3s_token}"
Environment="INSTALL_K3S_EXEC='agent' '--node-ip' '${node_ip}' '--kubelet-arg' '--cloud-provider=external'" Environment="INSTALL_K3S_EXEC=agent --node-ip=${node_ip} --kubelet-arg --cloud-provider=external"
ExecStart=/usr/bin/sh -c "/opt/k3s-install.sh" ExecStart=/usr/bin/sh -c "/opt/k3s-install.sh"
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
@ -33,5 +33,4 @@ storage:
- path: /opt/k3s-install.sh - path: /opt/k3s-install.sh
mode: 0777 mode: 0777
contents: contents:
remote: source: https://get.k3s.io
url: https://get.k3s.io

View file

@ -61,15 +61,7 @@ resource "hcloud_server" "machine" {
} }
provisioner "file" { provisioner "file" {
content = templatefile( content = data.ct_config.machine-ignitions[each.key].rendered
"${path.module}/configs/k3os-config.yml",
{
"host" = "${each.key}"
"k3s_token" = "${var.k3s_token}"
"datacenter" = "hel1-dc2"
"node_ip" = "${each.value.private_ip}"
}
)
destination = "/root/ignition.json" destination = "/root/ignition.json"
} }
@ -80,7 +72,7 @@ resource "hcloud_server" "machine" {
"curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install", "curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install",
"chmod +x flatcar-install", "chmod +x flatcar-install",
"./flatcar-install -s -i /root/ignition.json -C ${var.release_channel}", "./flatcar-install -s -i /root/ignition.json -C ${var.release_channel}",
"shutdown -r +1", "reboot",
] ]
on_failure = continue on_failure = continue
} }

View file

@ -2,8 +2,15 @@ k3os_workers = {
"worker1-gen2" = { "worker1-gen2" = {
backups = false backups = false
node_type = "worker" node_type = "worker"
server_type = "cpx11" server_type = "cpx21"
private_ip = "172.23.2.41" private_ip = "172.23.2.22"
}
"worker2-gen2" = {
backups = false
node_type = "worker"
server_type = "cpx21"
private_ip = "172.23.2.23"
} }
} }
@ -13,18 +20,6 @@ vms = {
server_type = "cpx11", server_type = "cpx11",
backups = true, backups = true,
private_ip = "172.23.2.10" private_ip = "172.23.2.10"
},
"worker1" = {
node_type = "worker"
server_type = "cpx21"
backups = false,
private_ip = "172.23.2.20"
},
"worker2" = {
node_type = "worker"
server_type = "cpx21"
backups = false,
private_ip = "172.23.2.21"
} }
} }
@ -37,3 +32,5 @@ ci_workers = {
} }
ssh_keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKfHZaI0F5GjAcrM8hjWqwMfULDkAZ2TOIBTQtRocg1F id_ed25519"] ssh_keys = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKfHZaI0F5GjAcrM8hjWqwMfULDkAZ2TOIBTQtRocg1F id_ed25519"]
release_channel = "stable"

View file

@ -1,5 +1,3 @@
# NOTE: this release was tested against kubernetes v1.18.x
--- ---
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
@ -67,6 +65,8 @@ spec:
cpu: 100m cpu: 100m
memory: 50Mi memory: 50Mi
env: env:
- name: HCLOUD_NETWORK_ROUTES_ENABLED
value: 'false'
- name: NODE_NAME - name: NODE_NAME
valueFrom: valueFrom:
fieldRef: fieldRef: