diff --git a/helm/longhorn.yaml b/helm/longhorn.yaml new file mode 100644 index 0000000..9c8c7a5 --- /dev/null +++ b/helm/longhorn.yaml @@ -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 diff --git a/init.tf b/init.tf index 54534f6..e16d02c 100644 --- a/init.tf +++ b/init.tf @@ -80,18 +80,24 @@ resource "null_resource" "kustomization" { content = yamlencode({ apiVersion = "kustomize.config.k8s.io/v1beta1" kind = "Kustomization" - 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/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", - ], local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [] - , var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : []), - patchesStrategicMerge = concat([ - 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")] : []) + resources = concat( + [ + "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://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml", + ], + var.disable_hetzner_csi ? [] : ["https://raw.githubusercontent.com/hetznercloud/csi-driver/${local.csi_version}/deploy/kubernetes/hcloud-csi.yml"], + local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [], + var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : [] + ), + patchesStrategicMerge = concat( + [ + 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" } @@ -161,6 +167,27 @@ resource "null_resource" "kustomization" { } 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 ] } diff --git a/modules/host/main.tf b/modules/host/main.tf index be7637d..2897fff 100644 --- a/modules/host/main.tf +++ b/modules/host/main.tf @@ -69,7 +69,7 @@ resource "hcloud_server" "server" { provisioner "remote-exec" { inline = [ "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 EOT } + + # Enable open-iscsi + provisioner "remote-exec" { + inline = [ + "set -ex", + "systemctl enable --now iscsid" + ] + } } resource "hcloud_server_network" "server" { diff --git a/terraform.tfvars.example b/terraform.tfvars.example index fceaafc..9571bc0 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -103,6 +103,12 @@ load_balancer_location = "fsn1" ### 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 # hetzner_ccm_version = "" # hetzner_csi_version = "" diff --git a/variables.tf b/variables.tf index 6ad438e..4994180 100644 --- a/variables.tf +++ b/variables.tf @@ -163,3 +163,15 @@ variable "cni_plugin" { default = "flannel" 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" +}