Add Longhorn and make it possible to enable/disable it and the hetzner csi

This commit is contained in:
Michael Karbowiak 2022-05-02 16:21:18 +02:00
parent 56ff30199d
commit f905b68e7c
5 changed files with 89 additions and 14 deletions

22
helm/longhorn.yaml Normal file
View File

@ -0,0 +1,22 @@
---
helmDefaults:
timeout: 3600
wait: true
force: false
atomic: true
repositories:
- name: longhorn
url: https://charts.longhorn.io
releases:
- name: longhorn
namespace: longhorn
chart: longhorn/longhorn
values:
- persistence:
defaultClass: true
defaultFsType: ext4
defaultClassReplicaCount: 2
- defaultSettings:
defaultDataPath: /var/longhorn

53
init.tf
View File

@ -80,18 +80,24 @@ resource "null_resource" "kustomization" {
content = yamlencode({ content = yamlencode({
apiVersion = "kustomize.config.k8s.io/v1beta1" apiVersion = "kustomize.config.k8s.io/v1beta1"
kind = "Kustomization" kind = "Kustomization"
resources = concat([ resources = concat(
"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/hetznercloud/hcloud-cloud-controller-manager/releases/download/${local.ccm_version}/ccm-networks.yaml",
"https://github.com/weaveworks/kured/releases/download/${local.kured_version}/kured-${local.kured_version}-dockerhub.yaml", "https://github.com/weaveworks/kured/releases/download/${local.kured_version}/kured-${local.kured_version}-dockerhub.yaml",
"https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml", "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml",
], local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [] ],
, var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : []), var.disable_hetzner_csi ? [] : ["https://raw.githubusercontent.com/hetznercloud/csi-driver/${local.csi_version}/deploy/kubernetes/hcloud-csi.yml"],
patchesStrategicMerge = concat([ local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [],
file("${path.module}/kustomize/kured.yaml"), var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : []
file("${path.module}/kustomize/ccm.yaml"), ),
file("${path.module}/kustomize/system-upgrade-controller.yaml") patchesStrategicMerge = concat(
], var.cni_plugin == "calico" ? [file("${path.module}/kustomize/calico.yaml")] : []) [
file("${path.module}/kustomize/kured.yaml"),
file("${path.module}/kustomize/ccm.yaml"),
file("${path.module}/kustomize/system-upgrade-controller.yaml")
],
var.cni_plugin == "calico" ? [file("${path.module}/kustomize/calico.yaml")] : []
)
}) })
destination = "/var/post_install/kustomization.yaml" destination = "/var/post_install/kustomization.yaml"
} }
@ -161,6 +167,27 @@ resource "null_resource" "kustomization" {
} }
depends_on = [ depends_on = [
null_resource.first_control_plane null_resource.first_control_plane,
local_sensitive_file.kubeconfig
]
}
resource "null_resource" "longhorn" {
# If longhorn isn't enabled, we don't want any Helm resources
count = var.enable_longhorn ? 1 : 0
# Install Helm charts
provisioner "local-exec" {
when = create
command = <<-EOT
export KUBECONFIG=$(readlink -f ${path.module}/kubeconfig.yaml)
helmfile -f ${path.module}/helm/longhorn.yaml apply
EOT
on_failure = continue
}
depends_on = [
null_resource.first_control_plane,
local_sensitive_file.kubeconfig
] ]
} }

View File

@ -69,7 +69,7 @@ resource "hcloud_server" "server" {
provisioner "remote-exec" { provisioner "remote-exec" {
inline = [ inline = [
"set -ex", "set -ex",
"transactional-update shell <<< 'rpm --import https://rpm.rancher.io/public.key;zypper install -y https://github.com/k3s-io/k3s-selinux/releases/download/v0.5.stable.1/k3s-selinux-0.5-1.sle.noarch.rpm'" "transactional-update shell <<< 'rpm --import https://rpm.rancher.io/public.key; zypper install -y open-iscsi https://github.com/k3s-io/k3s-selinux/releases/download/v0.5.stable.1/k3s-selinux-0.5-1.sle.noarch.rpm'"
] ]
} }
@ -84,6 +84,14 @@ resource "hcloud_server" "server" {
done done
EOT EOT
} }
# Enable open-iscsi
provisioner "remote-exec" {
inline = [
"set -ex",
"systemctl enable --now iscsid"
]
}
} }
resource "hcloud_server_network" "server" { resource "hcloud_server_network" "server" {

View File

@ -103,6 +103,12 @@ load_balancer_location = "fsn1"
### The following values are entirely optional ### The following values are entirely optional
# To use local storage on the nodes, you can enable Longhorn, default is "false"
# enable_longhorn = false
# To disable Hetzner CSI storage, you can set the following to true, default is "false"
# disable_hetzner_csi = false
# If you want to use a specific Hetzner CCM and CSI version, set them below; otherwise, leave them as-is for the latest versions # If you want to use a specific Hetzner CCM and CSI version, set them below; otherwise, leave them as-is for the latest versions
# hetzner_ccm_version = "" # hetzner_ccm_version = ""
# hetzner_csi_version = "" # hetzner_csi_version = ""

View File

@ -163,3 +163,15 @@ variable "cni_plugin" {
default = "flannel" default = "flannel"
description = "CNI plugin for k3s" description = "CNI plugin for k3s"
} }
variable "enable_longhorn" {
type = bool
default = false
description = "Enable Longhorn"
}
variable "disable_hetzner_csi" {
type = bool
default = false
description = "Disable hetzner csi driver"
}