Skip to content

Commit

Permalink
more indent
Browse files Browse the repository at this point in the history
  • Loading branch information
heyLu committed Oct 25, 2023
1 parent 1c44935 commit 9fcbcf7
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,95 +16,95 @@ A working example can be found in `examples/k8s`. The files inside manifests dir

1. wrap a configfile inside a configmap, and use `{{ .secretKey }}` as placeholder

```yaml
...
data:
index.html: |-
<h1>{{ .headline }}</h1>
...
```
```yaml
...
data:
index.html: |-
<h1>{{ .headline }}</h1>
...
```

2. provide secrets inside Kubernetes Secrets

```yaml
...
data:
secret-headline: dmFsdWVGcm9tU2VjcmV0
...
```
```yaml
...
data:
secret-headline: dmFsdWVGcm9tU2VjcmV0
...
```

3. configure an init-container using `k8s-multi-secret-to-file`, e.g.

```yaml
...
initContainers:
image: ghcr.io/spreadshirt/k8s-multi-secret-to-file:latest
imagePullPolicy: Always
name: secret-init
volumeMounts:
- mountPath: /etc/rendered
name: init-share
- mountPath: /etc/templates/index.html
name: configmap
subPath: index.html
...
```
```yaml
...
initContainers:
image: ghcr.io/spreadshirt/k8s-multi-secret-to-file:latest
imagePullPolicy: Always
name: secret-init
volumeMounts:
- mountPath: /etc/rendered
name: init-share
- mountPath: /etc/templates/index.html
name: configmap
subPath: index.html
...
```

4. provide secrets as environment variables to the init container. Envs must be prefixed (default: `SECRET_`)

```yaml
...
- env:
- name: SECRET_headline
valueFrom:
secretKeyRef:
name: apache-demo
key: secret-headline
...
```
```yaml
...
- env:
- name: SECRET_headline
valueFrom:
secretKeyRef:
name: apache-demo
key: secret-headline
...
```

5. configure [Volumes](https://kubernetes.io/docs/concepts/storage/volumes/) to allow interaction between the init-container and the application

```yaml
...
volumes:
- emptyDir: { }
name: init-share
- configMap:
name: apache-demo-cfg
name: configmap
...
```
```yaml
...
volumes:
- emptyDir: { }
name: init-share
- configMap:
name: apache-demo-cfg
name: configmap
...
```

6. mount configfile and target path to init-container (IMPORTANT: don't mount the configfile directly to the application container!)

```yaml
...
volumeMounts:
- mountPath: /etc/rendered
name: init-share
- mountPath: /etc/templates/index.html
name: configmap
subPath: index.html
...
```
```yaml
...
volumeMounts:
- mountPath: /etc/rendered
name: init-share
- mountPath: /etc/templates/index.html
name: configmap
subPath: index.html
...
```

`/etc/templates` and `/etc/rendered` are the default paths for templates and the results, this can be configured, if necessary
`/etc/templates` and `/etc/rendered` are the default paths for templates and the results, this can be configured, if necessary

7. mount the rendered config file to the application container

```yaml
...
volumeMounts:
- mountPath: /var/www/html/index.html
name: init-share
subPath: index.html
...
```
```yaml
...
volumeMounts:
- mountPath: /var/www/html/index.html
name: init-share
subPath: index.html
...
```

8. deploy the application and check the rendered file inside the application container

```sh
$ kubectl exec <POD_NAME> -c apache -- cat /var/www/html/index.html
<h1>valueFromSecret</h1>
```
```sh
$ kubectl exec <POD_NAME> -c apache -- cat /var/www/html/index.html
<h1>valueFromSecret</h1>
```

0 comments on commit 9fcbcf7

Please sign in to comment.