doc: add environment variable template example (#9019)

* doc: add environment variable template example

* Update website/pages/docs/platform/k8s/injector/examples.mdx

Co-authored-by: Becca Petrin <beccapetrin@gmail.com>

Co-authored-by: Becca Petrin <beccapetrin@gmail.com>
This commit is contained in:
Jason O'Donnell 2020-05-18 15:51:17 -04:00 committed by GitHub
parent ac880b0079
commit 0eba895a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -233,3 +233,45 @@ data:
"client_key" = "/vault/tls/client.key"
}
```
## Environment Variable Example
The following example demonstrates how templates can be used to create environment
variables. A template should be created that exports a Vault secret as an environment
variable and the application container should source those files during startup.
```yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
labels:
app: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "web"
vault.hashicorp.com/agent-inject-secret-config: "secret/data/web"
# Environment variable export template
vault.hashicorp.com/agent-inject-template-config: |
{{ with secret "secret/data/web" -}}
export api_key="{{ .Data.data.payments_api_key }}"
{{- end }}
spec:
serviceAccountName: web
containers:
- name: web
image: alpine:latest
args: ["sh", "-c", "source /vault/secrets/config && <entrypoint script>"]
ports:
- containerPort: 9090
```