Skip to content

Commit 96b29cc

Browse files
author
Markus Heinemann
committed
Update kustomization_user_deploy docs and examples
1 parent bd94d97 commit 96b29cc

18 files changed

+218
-147
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ As Cilium has a lot of interesting and powerful config possibilities, we give yo
178178

179179
Cilium supports full kube-proxy replacement. Cilium runs by default in hybrid kube-proxy replacement mode. To achieve a completely kube-proxy-free cluster, set `disable_kube_proxy = true`.
180180

181-
It is also possible to enable Hubble using `cilium_hubble_enabled = true`. In order to access the Hubble UI, you need to port-forward the Hubble UI service to your local machine. By default, you can do this by running `kubectl port-forward -n kube-system service/hubble-ui 12000:80` and then opening `http://localhost:12000` in your browser.
181+
It is also possible to enable Hubble using `cilium_hubble_enabled = true`. In order to access the Hubble UI, you need to port-forward the Hubble UI service to your local machine. By default, you can do this by running `kubectl port-forward -n kube-system service/hubble-ui 12000:80` and then opening `http://localhost:12000` in your browser.
182182
However, it is recommended to use the [Cilium CLI](https://docs.cilium.io/en/stable/gettingstarted/k8s-install-default/#install-the-cilium-cli) and [Hubble Client](https://docs.cilium.io/en/stable/gettingstarted/k8s-install-default/#install-the-cilium-cli) and running the `cilium hubble ui` command.
183183

184184
## Scaling Nodes
@@ -293,7 +293,7 @@ If you need to install additional Helm charts or Kubernetes manifests that are n
293293

294294
These files need to be valid `Kustomization` manifests, additionally supporting terraform templating! (The templating parameters can be passed via the `extra_kustomize_parameters` variable (via a map) to the module).
295295

296-
All files in the `extra-manifests` directory including the rendered versions of the `*.yaml.tpl` will be applied to k3s with `kubectl apply -k` (which will be executed after and independently of the basic cluster configuration).
296+
All files in the `extra-manifests` directory and its subdirectories including the rendered versions of the `*.yaml.tpl` will be applied to k3s with `kubectl apply -k` (which will be executed after and independently of the basic cluster configuration).
297297

298298
See a working example in [examples/kustomization_user_deploy](https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner/tree/master/examples/kustomization_user_deploy).
299299

+132-21
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,145 @@
11
# How install deploy a additional / extra stuff while terraforming the cluster
22

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.
44

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`.
76

8-
### Assuming you followed the `DO not Skip` part of the installation
7+
## Examples
98

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.
1510

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.
1712
18-
Assuming no errors have been made, apply this by run `terraform apply`<br>
13+
### Deploying simple resources
1914

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`.
2116

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`
2418

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
2655

2756
Check what kustomization exists:
2857

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+
```

examples/kustomization_user_deploy/extra-manifests/cert-manager-webhook-inwx.yaml.tpl

-60
This file was deleted.

examples/kustomization_user_deploy/extra-manifests/some-random-name.yaml.tpl

-61
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: helm.cattle.io/v1
2+
kind: HelmChart
3+
metadata:
4+
name: argocd
5+
namespace: argocd
6+
spec:
7+
repo: https://argoproj.github.io/argo-helm
8+
chart: argo-cd
9+
targetNamespace: argocd
10+
valuesContent: |-
11+
global:
12+
domain: argocd.example.com
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- helm-chart.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: argocd

examples/kustomization_user_deploy/mutliple-namespaces/base/kustomization.yaml.tpl

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: myapp-pod
5+
labels:
6+
app: myapp
7+
spec:
8+
containers:
9+
- name: nginx
10+
image: nginx:1.7.9

examples/kustomization_user_deploy/extra-manifests/kustomization.yaml.tpl renamed to examples/kustomization_user_deploy/mutliple-namespaces/kustomization.yaml.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
33

44
resources:
5-
- some-random-name.yaml
6-
- cert-manager-webhook-inwx.yaml
5+
- namespace-a
6+
- namespace-b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- ../base
7+
namespace: namespace-a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: namespace-a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- ../base
7+
namespace: namespace-b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: namespace-b
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: demo-config
5+
data:
6+
someConfigKey: ${sealed_secrets_crt}

0 commit comments

Comments
 (0)