feat: switch to litestream backup

This commit is contained in:
Peter 2024-10-28 11:40:28 +01:00
parent f29ef0bdb5
commit e9afbb2f9f
Signed by: prskr
GPG key ID: F56BED6903BC5E37
5 changed files with 12 additions and 28 deletions

View file

@ -27,7 +27,6 @@ systemd:
Wants = network-online.target Wants = network-online.target
After = network.target network-online.target litestream.service After = network.target network-online.target litestream.service
ConditionPathExists=/opt/k3s-install.sh ConditionPathExists=/opt/k3s-install.sh
ConditionPathExists=/mnt/HC_Volume_${volume_id}
ConditionPathExists=!/opt/k3s/bin/k3s ConditionPathExists=!/opt/k3s/bin/k3s
[Service] [Service]
@ -48,7 +47,7 @@ systemd:
Environment="K3S_TOKEN=${k3s_token}" Environment="K3S_TOKEN=${k3s_token}"
Environment="INSTALL_K3S_VERSION=${k3s_version}" Environment="INSTALL_K3S_VERSION=${k3s_version}"
Environment="INSTALL_K3S_BIN_DIR=/opt/k3s" Environment="INSTALL_K3S_BIN_DIR=/opt/k3s"
Environment="INSTALL_K3S_EXEC=server --data-dir /mnt/HC_Volume_${volume_id}/k3s --advertise-address 172.23.2.10 --node-ip ${node_ip} --node-taint=node-type=k3s-controlplane:NoSchedule %{for san in k3s_sans }--tls-san='${san}' %{endfor} --disable-cloud-controller --disable servicelb --kubelet-arg=cloud-provider=external" Environment="INSTALL_K3S_EXEC=server --data-dir /var/lib/rancher/k3s --advertise-address 172.23.2.10 --node-ip ${node_ip} --node-taint=node-type=k3s-controlplane:NoSchedule %{for san in k3s_sans }--tls-san='${san}' %{endfor} --disable-cloud-controller --disable servicelb --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]

View file

@ -4,10 +4,11 @@ secret-access-key: ${secretKey}
dbs: dbs:
- path: /var/lib/rancher/k3s/server/db/state.db - path: /var/lib/rancher/k3s/server/db/state.db
replicas: replicas:
- name: Garage - name: Hcloud
type: s3 type: s3
path: litestream/k3s
endpoint: ${endpoint} endpoint: ${endpoint}
bucket: k3s bucket: 1661580-backup
region: hel1 region: auto
retention: 24h retention: 4h
snapshot-interval: 15m snapshot-interval: 15m

View file

@ -11,14 +11,6 @@ resource "null_resource" "control_plane_generation" {
} }
} }
resource "hcloud_volume" "cp-k3s-storage" {
for_each = var.k3s_control_plane
name = "${each.key}-k3s-storage"
size = 15
format = "ext4"
delete_protection = true
}
resource "hcloud_server" "control-plane" { resource "hcloud_server" "control-plane" {
for_each = var.k3s_control_plane for_each = var.k3s_control_plane
name = each.key name = each.key
@ -96,13 +88,6 @@ resource "hcloud_server" "control-plane" {
} }
} }
resource "hcloud_volume_attachment" "cp-k3s-storage" {
for_each = var.k3s_control_plane
volume_id = hcloud_volume.cp-k3s-storage[each.key].id
server_id = hcloud_server.control-plane[each.key].id
automount = true
}
resource "cloudflare_record" "cp-host-ipv4" { resource "cloudflare_record" "cp-host-ipv4" {
for_each = var.k3s_control_plane for_each = var.k3s_control_plane
@ -147,7 +132,6 @@ data "ct_config" "machine-ignitions-cp" {
"node_ip" = "${each.value.private_ip}" "node_ip" = "${each.value.private_ip}"
"k3s_version" = "${var.control_plane_k3s_version}", "k3s_version" = "${var.control_plane_k3s_version}",
"k3s_sans" = var.k3s_sans, "k3s_sans" = var.k3s_sans,
"volume_id" = hcloud_volume.cp-k3s-storage[each.key].id
} }
) )
snippets = [ snippets = [

View file

@ -136,7 +136,7 @@ resource "null_resource" "machine-drainable" {
provisioner "local-exec" { provisioner "local-exec" {
when = destroy when = destroy
on_failure = continue on_failure = continue
command = "kubectl drain --delete-emptydir-data=true --ignore-daemonsets=true ${each.key}" command = "kubectl drain --delete-emptydir-data=true --ignore-daemonsets=true --disable-eviction ${each.key}"
} }
} }

View file

@ -39,12 +39,12 @@ variable "litestream_version" {
variable "control_plane_k3s_version" { variable "control_plane_k3s_version" {
type = string type = string
default = "v1.30.4+k3s1" default = "v1.30.5+k3s1"
} }
variable "worker_k3s_version" { variable "worker_k3s_version" {
type = string type = string
default = "v1.30.4+k3s1" default = "v1.30.5+k3s1"
} }
variable "k3s_sans" { variable "k3s_sans" {