-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1314 from markusheinemann/master
Add recursive user manifests
- Loading branch information
Showing
19 changed files
with
153 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,72 @@ | ||
# How install deploy a additional / extra stuff while terraforming the cluster | ||
# How to Install and Deploy Additional Resources with Terraform and Kube-Hetzner | ||
|
||
## With a `HelmChart` and `HelmChartConfig` | ||
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. | ||
|
||
This is how it worked for me, note I'm a total beginner with kustomize.<br> | ||
Pretty sure I butchered a lot ;) | ||
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. | ||
|
||
### Assuming you followed the `DO not Skip` part of the installation | ||
## Examples | ||
|
||
In the project folder, where the `kube.tf` is located: | ||
1. Create a folder named `extra-manifests`. | ||
2. In it create a file named `kustomization.yaml.tpl` and **your** manifest file(s). Be sure to use the `resources` field, in the `kustomization.yaml` file, to define the list of resources to include in a configuration. | ||
Here are some examples of common use cases for deploying additional resources: | ||
|
||
## Apply the kustomized configuration | ||
> **Note**: When trying out the demos, make sure that the files from the demo folders are located in the `extra-manifests` directory. | ||
Assuming no errors have been made, apply this by run `terraform apply`<br> | ||
### Deploying Simple Resources | ||
|
||
## ReRun the kustomization (debugging) | ||
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. | ||
|
||
In the highly unlikely case that an actual error has occurred...<br> | ||
Anyway, you can rerun just the kustomization part like this: | ||
#### `kube.tf` | ||
|
||
```sh | ||
terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve | ||
``` | ||
|
||
Check what kustomization exists: | ||
|
||
```sh | ||
(⎈|dev3:default)➜ dev3-cluster (main) ✗ terraform state list | grep kustom | ||
... | ||
module.kube-hetzner.null_resource.kustomization | ||
module.kube-hetzner.null_resource.kustomization_user["some-random-name.yaml.tpl"] | ||
module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] | ||
extra_kustomize_parameters = { | ||
my_config_key = "somestring" | ||
} | ||
... | ||
``` | ||
|
||
The variable defined in `kube.tf` can be used in any `.yaml.tpl` manifest. | ||
|
||
#### `configmap.tf` | ||
|
||
``` | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: demo-config | ||
data: | ||
someConfigKey: ${sealed_secrets_crt} | ||
``` | ||
|
||
For a full demo see the [simple-resources](simple-resources/) example. | ||
|
||
### Deploying a Helm Chart | ||
|
||
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`. | ||
|
||
For a full demo see the [helm-chart](helm-chart/) example. | ||
|
||
### Multiple Namespaces | ||
|
||
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`. | ||
|
||
For a full demo see the [multiple-namespaces](multiple-namespaces/) example. | ||
|
||
## Debugging | ||
|
||
To check the existing kustomization, you can run the following command: | ||
|
||
``` | ||
$ terraform state list | grep kustom | ||
... | ||
module.kube-hetzner.null_resource.kustomization | ||
module.kube-hetzner.null_resource.kustomization_user["demo-config-map.yaml.tpl"] | ||
module.kube-hetzner.null_resource.kustomization_user["demo-pod.yaml.tpl"] | ||
module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"] | ||
... | ||
``` | ||
|
||
If you want to rerun just the kustomization part, you can use the following command: | ||
|
||
``` | ||
terraform apply -replace='module.kube-hetzner.null_resource.kustomization_user["kustomization.yaml.tpl"]' --auto-approve | ||
``` |
60 changes: 0 additions & 60 deletions
60
examples/kustomization_user_deploy/extra-manifests/cert-manager-webhook-inwx.yaml.tpl
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
examples/kustomization_user_deploy/extra-manifests/some-random-name.yaml.tpl
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
examples/kustomization_user_deploy/helm-chart/helm-chart.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: helm.cattle.io/v1 | ||
kind: HelmChart | ||
metadata: | ||
name: argocd | ||
namespace: argocd | ||
spec: | ||
repo: https://argoproj.github.io/argo-helm | ||
chart: argo-cd | ||
targetNamespace: argocd | ||
valuesContent: |- | ||
global: | ||
domain: argocd.example.com |
6 changes: 6 additions & 0 deletions
6
examples/kustomization_user_deploy/helm-chart/kustomize.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- namespace.yaml | ||
- helm-chart.yaml |
4 changes: 4 additions & 0 deletions
4
examples/kustomization_user_deploy/helm-chart/namespace.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: argocd |
Empty file.
10 changes: 10 additions & 0 deletions
10
examples/kustomization_user_deploy/mutliple-namespaces/base/pod.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: myapp-pod | ||
labels: | ||
app: myapp | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.7.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
examples/kustomization_user_deploy/mutliple-namespaces/namespace-a/kustomization.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- namespace.yaml | ||
- ../base | ||
namespace: namespace-a |
4 changes: 4 additions & 0 deletions
4
examples/kustomization_user_deploy/mutliple-namespaces/namespace-a/namespace-a.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: namespace-a |
7 changes: 7 additions & 0 deletions
7
examples/kustomization_user_deploy/mutliple-namespaces/namespace-b/kustomization.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- namespace.yaml | ||
- ../base | ||
namespace: namespace-b |
4 changes: 4 additions & 0 deletions
4
examples/kustomization_user_deploy/mutliple-namespaces/namespace-b/namespace-b.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: namespace-b |
6 changes: 6 additions & 0 deletions
6
examples/kustomization_user_deploy/simple-resources/demo-config-map.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: demo-config | ||
data: | ||
someConfigKey: ${sealed_secrets_crt} |
16 changes: 16 additions & 0 deletions
16
examples/kustomization_user_deploy/simple-resources/demo-pod.yml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: demo | ||
spec: | ||
containers: | ||
- name: demo-container | ||
image: registry.k8s.io/busybox | ||
command: [ "/bin/sh", "-c", "env" ] | ||
env: | ||
- name: DEMO_ENVIRONEMNT_VARIABLE | ||
valueFrom: | ||
configMapKeyRef: | ||
name: demo-config | ||
key: someConfigKey | ||
restartPolicy: Never |
5 changes: 5 additions & 0 deletions
5
examples/kustomization_user_deploy/simple-resources/kustomization.yaml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- demo-config-map.yaml.tpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters