|
1 | 1 | # How install deploy a additional / extra stuff while terraforming the cluster
|
2 | 2 |
|
3 |
| -## With a `HelmChart` and `HelmChartConfig` |
| 3 | +Kube-Hetzner allows to provide user-defined resources after the initial setup of the Kubernetes cluster. Additional Kustomize scripts in the `extra-manifests` directory with the extension `.yaml.tpl` are recursively copied onto the control plane and are deployed with `kubectl apply -k`. The main entry point is the file called `kustomization.yaml.tpl`. Therefor the names of other manifests must be listed in the `kustomization.yaml.tpl` `recources` without the `.tpl` extension. |
4 | 4 |
|
5 |
| -This is how it worked for me, note I'm a total beginner with kustomize.<br> |
6 |
| -Pretty sure I butchered a lot ;) |
| 5 | +The manifests are deployed automaticly when executing `terrafrom apply`. |
7 | 6 |
|
8 |
| -### Assuming you followed the `DO not Skip` part of the installation |
| 7 | +## Examples |
9 | 8 |
|
10 |
| -In the project folder, where the `kube.tf` is located.<br> |
11 |
| -Create a folder named `extra-manifests`<br> |
12 |
| -In it create a file named `kustomization.yaml.tpl`<br> |
13 |
| -and **your** manifest file(s), there names must be listed in the `kustomization.yaml.tpl` `recources` without the `.tpl`<br> |
14 |
| -e.g. `some-random-name.yaml.tpl` |
| 9 | +Some examples for the most common usecases are provided. |
15 | 10 |
|
16 |
| -## Apply the kustomized configuration |
| 11 | +> When tring out the demos, make sure that the files from the demo folders are located in the `extra-manifests` directory. |
17 | 12 |
|
18 |
| -Assuming no errors have been made, apply this by run `terraform apply`<br> |
| 13 | +### Deploying simple resources |
19 | 14 |
|
20 |
| -## ReRun the kustomization (debugging) |
| 15 | +The easiest use case is to deploy some simple resources to the cluster. Since the kustomize resources are [terrafrom template files](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) the can make use of parameters provided in the `extra_kustomize_parameters` map of the `kube.tf`. |
21 | 16 |
|
22 |
| -In the highly unlikely case that an actual error has occurred...<br> |
23 |
| -Anyway, you can rerun just the kustomization part like this: |
| 17 | +#### `kube.tf` |
24 | 18 |
|
25 |
| - terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve |
| 19 | +```tf |
| 20 | +... |
| 21 | +extra_kustomize_parameters = { |
| 22 | + my_config_key = "somestring" |
| 23 | +} |
| 24 | +... |
| 25 | +``` |
| 26 | + |
| 27 | +The variable can be used in any `.yaml.tpl` manifest |
| 28 | + |
| 29 | +#### `configmap.tf` |
| 30 | + |
| 31 | +``` |
| 32 | +apiVersion: v1 |
| 33 | +kind: ConfigMap |
| 34 | +metadata: |
| 35 | + name: demo-config |
| 36 | + data: |
| 37 | + someConfigKey: ${sealed_secrets_crt} |
| 38 | +``` |
| 39 | + |
| 40 | +For a full example see [simple-resources](simple-resources/) |
| 41 | + |
| 42 | +### Deploying a Helm Chart |
| 43 | + |
| 44 | +You may want to deploy a helm chart to your cluster. K3s includes a [Helm Chart controller](https://docs.k3s.io/helm) which provides the CRDs `HelmChart` and `HelmChartConfig`. |
| 45 | + |
| 46 | +For a full demo see the [helm-chart](helm-chart/) example. |
| 47 | + |
| 48 | +### Multiple Namespaces |
| 49 | + |
| 50 | +In some more complex uses cases you may want to deploy to multi namespaces with a common base. This behaviour is [supported by Kustomize](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/multibases/multi-namespace.md) and can be done with Kube-Hetzner since it considers all subdirectors of `extra-manifests` as well. |
| 51 | + |
| 52 | +For a full demo see the [multiple-namespaces](multiple-namespaces/) example. |
| 53 | + |
| 54 | +## Debugging |
26 | 55 |
|
27 | 56 | Check what kustomization exists:
|
28 | 57 |
|
29 |
| - (⎈|dev3:default)➜ dev3-cluster (main) ✗ terraform state list | grep kustom |
30 |
| - ... |
31 |
| - module.kube-hetzner.null_resource.kustomization |
32 |
| - module.kube-hetzner.null_resource.kustomization_user["some-random-name.yaml.tpl"] |
33 |
| - module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] |
34 |
| - ... |
| 58 | +``` |
| 59 | +$ terraform state list | grep kustom |
| 60 | + ... |
| 61 | + module.kube-hetzner.null_resource.kustomization |
| 62 | + module.kube-hetzner.null_resource.kustomization_user["demo-config-map.yaml.tpl"] |
| 63 | + module.kube-hetzner.null_resource.kustomization_user["demo-pod.yaml.tpl"] |
| 64 | + module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] |
| 65 | + ... |
| 66 | +``` |
| 67 | + |
| 68 | +You can rerun just the kustomization part like this: |
| 69 | + |
| 70 | +``` |
| 71 | +terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve |
| 72 | +``` |
| 73 | + |
| 74 | +# How to Install and Deploy Additional Resources with Terraform and Kube-Hetzner |
| 75 | + |
| 76 | +Kube-Hetzner allows you to provide user-defined resources after the initial setup of the Kubernetes cluster. You can deploy additional resources using Kustomize scripts in the `extra-manifests` directory with the extension `.yaml.tpl`. These scripts are recursively copied onto the control plane and deployed with `kubectl apply -k`. The main entry point for these additional resources is the `kustomization.yaml.tpl` file. In this file, you need to list the names of other manifests without the `.tpl` extension in the resources section. |
| 77 | + |
| 78 | +When you execute terraform apply, the manifests in the extra-manifests directory, including the rendered versions of the `*.yaml.tpl` files, will be automatically deployed to the cluster. |
| 79 | + |
| 80 | +## Examples |
| 81 | + |
| 82 | +Here are some examples of common use cases for deploying additional resources: |
| 83 | + |
| 84 | +> **Note**: When trying out the demos, make sure that the files from the demo folders are located in the `extra-manifests` directory. |
| 85 | +
|
| 86 | +### Deploying Simple Resources |
| 87 | + |
| 88 | +The easiest use case is to deploy simple resources to the cluster. Since the Kustomize resources are [Terraform template](https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/file) files, they can make use of parameters provided in the `extra_kustomize_parameters` map of the `kube.tf` file. |
| 89 | + |
| 90 | +#### **`kube.tf`** |
| 91 | + |
| 92 | +``` |
| 93 | +... |
| 94 | +extra_kustomize_parameters = { |
| 95 | + my_config_key = "somestring" |
| 96 | +} |
| 97 | +... |
| 98 | +``` |
| 99 | + |
| 100 | +The variable defined in `kube.tf` can be used in any `.yaml.tpl` manifest. |
| 101 | + |
| 102 | +#### **`configmap.tf`** |
| 103 | + |
| 104 | +``` |
| 105 | +apiVersion: v1 |
| 106 | +kind: ConfigMap |
| 107 | +metadata: |
| 108 | + name: demo-config |
| 109 | + data: |
| 110 | + someConfigKey: ${sealed_secrets_crt} |
| 111 | +``` |
| 112 | + |
| 113 | +For a full example, you can refer to the [simple-resources](simple-resources/) demo. |
| 114 | + |
| 115 | +### Deploying a Helm Chart |
| 116 | + |
| 117 | +If you want to deploy a Helm chart to your cluster, you can use the [Helm Chart controller](https://docs.k3s.io/helm) included in K3s. The Helm Chart controller provides the CRDs `HelmChart` and `HelmChartConfig`. |
| 118 | + |
| 119 | +For a full demo see the [helm-chart](helm-chart/) example. |
| 120 | + |
| 121 | +### Multiple Namespaces |
| 122 | + |
| 123 | +In more complex use cases, you may want to deploy to multiple namespaces with a common base. Kustomize supports this behavior, and it can be since Kube-Hetzner is considering all subdirectories of `extra-manifests`. |
| 124 | + |
| 125 | +For a full demo see the [multiple-namespaces](multiple-namespaces/) example. |
| 126 | + |
| 127 | +## Debugging |
| 128 | + |
| 129 | +To check the existing kustomization, you can run the following command: |
| 130 | + |
| 131 | +``` |
| 132 | +$ terraform state list | grep kustom |
| 133 | + ... |
| 134 | + module.kube-hetzner.null_resource.kustomization |
| 135 | + module.kube-hetzner.null_resource.kustomization_user["demo-config-map.yaml.tpl"] |
| 136 | + module.kube-hetzner.null_resource.kustomization_user["demo-pod.yaml.tpl"] |
| 137 | + module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] |
| 138 | + ... |
| 139 | +``` |
| 140 | + |
| 141 | +If you want to rerun just the kustomization part, you can use the following command: |
| 142 | + |
| 143 | +``` |
| 144 | +terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve |
| 145 | +``` |
0 commit comments