Add Longhorn and make it possible to enable/disable it and the hetzner csi
This commit is contained in:
parent
56ff30199d
commit
f905b68e7c
22
helm/longhorn.yaml
Normal file
22
helm/longhorn.yaml
Normal 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
53
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
|
||||
]
|
||||
}
|
||||
|
@ -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" {
|
||||
|
@ -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 = ""
|
||||
|
12
variables.tf
12
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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user