Skip to content

Commit 95f1875

Browse files
authored
Merge pull request #176 from kube-hetzner/rancher
Rancher addon
2 parents ebe1a27 + 75a817e commit 95f1875

File tree

6 files changed

+136
-4
lines changed

6 files changed

+136
-4
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,29 @@ To use Kube-Hetzner on Terraform cloud, use as a Terraform module as mentioned a
229229

230230
</details>
231231

232+
<details>
233+
234+
<summary>Configure add-ons with HelmChartConfig</summary>
235+
236+
For instance, to customize the Rancher install, if you choose to enable it, you can create and apply the following `HelmChartConfig`:
237+
238+
```yaml
239+
apiVersion: helm.cattle.io/v1
240+
kind: HelmChartConfig
241+
metadata:
242+
name: rancher
243+
namespace: kube-system
244+
spec:
245+
valuesContent: |-
246+
**values.yaml content you want to customize**
247+
```
248+
249+
The helm options for Rancher can be seen here <https://github.com/rancher/rancher/blob/release/v2.6/chart/values.yaml>.
250+
251+
Same goes for all add-ons, like Longhorn, Cert-manager, and Traefik.
252+
253+
</details>
254+
232255
## Debugging
233256
234257
First and foremost, it depends, but it's always good to have a quick look into Hetzner quickly without logging in to the UI. That is where the `hcloud` cli comes in.

init.tf

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ resource "null_resource" "kustomization" {
8888
"https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml",
8989
],
9090
var.disable_hetzner_csi ? [] : ["https://raw.githubusercontent.com/hetznercloud/csi-driver/${local.csi_version}/deploy/kubernetes/hcloud-csi.yml"],
91-
var.enable_longhorn ? ["longhorn.yaml"] : [],
9291
local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [],
93-
var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : []
92+
var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : [],
93+
var.enable_longhorn ? ["longhorn.yaml"] : [],
94+
var.enable_cert_manager || var.enable_rancher ? ["cert-manager.yaml"] : [],
95+
var.enable_rancher ? ["rancher.yaml"] : [],
9496
),
9597
patchesStrategicMerge = concat(
9698
[
@@ -160,6 +162,26 @@ resource "null_resource" "kustomization" {
160162
destination = "/var/post_install/longhorn.yaml"
161163
}
162164

165+
# Upload the cert-manager config
166+
provisioner "file" {
167+
content = templatefile(
168+
"${path.module}/templates/cert-manager.yaml.tpl",
169+
{})
170+
destination = "/var/post_install/cert-manager.yaml"
171+
}
172+
173+
# Upload the Rancher config
174+
provisioner "file" {
175+
content = templatefile(
176+
"${path.module}/templates/rancher.yaml.tpl",
177+
{
178+
rancher_install_channel = var.rancher_install_channel
179+
rancher_hostname = var.rancher_hostname
180+
number_control_plane_nodes = length(local.control_plane_nodes)
181+
})
182+
destination = "/var/post_install/rancher.yaml"
183+
}
184+
163185
# Deploy secrets, logging is automatically disabled due to sensitive variables
164186
provisioner "remote-exec" {
165187
inline = [

templates/cert-manager.yaml.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: cert-manager
6+
---
7+
apiVersion: helm.cattle.io/v1
8+
kind: HelmChart
9+
metadata:
10+
name: cert-manager
11+
namespace: kube-system
12+
spec:
13+
chart: cert-manager
14+
repo: https://charts.jetstack.io
15+
targetNamespace: cert-manager
16+
valuesContent: |-
17+
installCRDs: true

templates/rancher.yaml.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: cattle-system
6+
---
7+
apiVersion: helm.cattle.io/v1
8+
kind: HelmChart
9+
metadata:
10+
name: rancher
11+
namespace: kube-system
12+
spec:
13+
chart: rancher
14+
repo: https://releases.rancher.com/server-charts/${rancher_install_channel}
15+
targetNamespace: cattle-system
16+
valuesContent: |-
17+
ingress:
18+
tls:
19+
source: rancher
20+
hostname: ${rancher_hostname}
21+
replicas: ${number_control_plane_nodes}

terraform.tfvars.example

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private_key = "/home/username/.ssh/id_ed25519"
1818
network_region = "eu-central" # change to `us-east` if location is ash
1919

2020
# For the control planes, at least three nodes are the minimum for HA. Otherwise, you need to turn off the automatic upgrade (see ReadMe).
21-
# As per rancher docs, it must always be an odd number, never even! See https://rancher.com/docs/k3s/latest/en/installation/ha-embedded/
21+
# As per Rancher docs, it must always be an odd number, never even! See https://rancher.com/docs/k3s/latest/en/installation/ha-embedded/
2222
# For instance, one is ok (non-HA), two is not ok, and three is ok (becomes HA). It does not matter if they are in the same nodepool or not! So they can be in different locations and of various types.
2323

2424
# Of course, you can choose any number of nodepools you want, with the location you want. The only constraint on the location is that you need to stay in the same network region, Europe, or the US.
@@ -183,3 +183,23 @@ load_balancer_location = "fsn1"
183183
# If you want to disable the automatic use of placement group "spread". See https://docs.hetzner.com/cloud/placement-groups/overview/
184184
# That may be useful if you need to deploy more than 500 nodes! The default is "false".
185185
# placement_group_disable = true
186+
187+
# You can enable cert-manager (installed by Helm behind the scenes) with the following flag, the default is "false".
188+
# enable_cert_manager = true
189+
190+
# You can enable Rancher (installed by Helm behind the scenes) with the following flag, the default is "false".
191+
# When Rancher is enabled, it automatically installs cert-manager too, and it uses rancher's own certificates.
192+
# As for the number of replicas, it is set to the numbe of control plane nodes.
193+
# You can customized all of the above by creating and applying a HelmChartConfig to pass the helm chart values of your choice.
194+
# See https://rancher.com/docs/k3s/latest/en/helm/
195+
# and https://rancher.com/docs/rancher/v2.6/en/installation/install-rancher-on-k8s/chart-options/
196+
# enable_rancher = true
197+
198+
# When Rancher is deployed, by default is uses the "stable" channel. But this can be customized.
199+
# The allowed values are "stable", "latest", and "alpha".
200+
# rancher_install_channel = "latest"
201+
202+
# Set your Rancher hostname, the default is "rancher.example.com".
203+
# It is a required value when using rancher, but up to you to point the DNS to it or not.
204+
# You can also not point the DNS, and just port-forward locally via kubectl to get access to the dashboard.
205+
# rancher_hostname = "rancher.xyz.dev"

variables.tf

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ variable "initial_k3s_channel" {
107107
description = "Allows you to specify an initial k3s channel"
108108

109109
validation {
110-
condition = contains(["stable", "latest", "testing", "v1.16", "v1.17", "v1.18", "v1.19", "v1.20", "v1.21", "v1.22", "v1.23"], var.initial_k3s_channel)
110+
condition = contains(["stable", "latest", "testing", "v1.16", "v1.17", "v1.18", "v1.19", "v1.20", "v1.21", "v1.22", "v1.23", "v1.24"], var.initial_k3s_channel)
111111
error_message = "The initial k3s channel must be one of stable, latest or testing."
112112
}
113113
}
@@ -175,3 +175,32 @@ variable "disable_hetzner_csi" {
175175
default = false
176176
description = "Disable hetzner csi driver"
177177
}
178+
179+
variable "enable_cert_manager" {
180+
type = bool
181+
default = false
182+
description = "Enable cert manager"
183+
}
184+
185+
variable "enable_rancher" {
186+
type = bool
187+
default = false
188+
description = "Enable rancher"
189+
}
190+
191+
variable "rancher_install_channel" {
192+
type = string
193+
default = "stable"
194+
description = "Rancher install channel"
195+
196+
validation {
197+
condition = contains(["stable", "latest", "alpha"], var.rancher_install_channel)
198+
error_message = "The allowed values for the Rancher install channel are stable, latest, or alpha."
199+
}
200+
}
201+
202+
variable "rancher_hostname" {
203+
type = string
204+
default = "rancher.example.com"
205+
description = "Enable rancher"
206+
}

0 commit comments

Comments
 (0)