Table of Contents
- Prerequisites
- Vault Annotation Overview
- 1. Injecting the Full Secret Map
- 2. Rendering a Single Field with Templates
- 3. Injecting Multiple Secrets with Templates
- Pod Initialization and Containers
- Conclusion
- References
Prerequisites
- A running Kubernetes cluster (v1.16+).
- A Vault server with KV v2 secrets stored at
crds/data/mysql. - An existing
phpDeployment applied in your cluster.
When using KV v2, remember that paths include
/data/ (e.g., crds/data/mysql).Vault Annotation Overview
Vault annotations fall into two main categories:
Below is a quick reference for the five annotations used in this demo:
1. Injecting the Full Secret Map
By default, the Vault Agent Injector writes both the data and metadata of a KV secret into a single file.-
Create
patch-annotations.yaml: -
Apply the patch:
-
Verify the injected content:
Output:
2. Rendering a Single Field with Templates
To extract only a specific field (e.g.,username), use a templating annotation.
-
Create
patch-annotations-template.yaml: -
Apply the patch and wait for the new Pod:
-
Confirm the output:
Expected:
3. Injecting Multiple Secrets with Templates
You can inject several secrets into separate files by defining multiple<name> annotations.
-
Create
patch-annotations-multi.yaml: -
Apply the patch:
-
List the injected files:
Expected:
-
Verify each secret:
Pod Initialization and Containers
After applying annotations, inspect the Pod:- vault-agent-init (initContainer)
- vault-agent (sidecar)
- php (your application)
/vault/secrets.
Conclusion
In this demo, you learned how to:- Enable full secret map injection
- Render specific secret fields with templates
- Inject multiple secrets into separate files