This guide shows a simple PHP application that reads secrets injected into the pod filesystem by HashiCorp Vault (via Vault Agent Injector) and displays them in a minimal UI. It walks through cloning the repository, building the Docker image, deploying to Kubernetes, patching the Deployment with Vault annotations, and verifying that the app can read the injected secrets. Repository: https://github.com/sidd-harth/php-vault-example Quick start — clone, build, and prepareDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Demonstrates secret injection into pod filesystem using Vault Agent Injector.
- Shows how a simple PHP app reads files mounted at predetermined paths.
- Useful for learning pod-level secret access patterns and Vault integration with Kubernetes.
- The PHP app expects these files (mounted by the Vault injector) at runtime:
- /vault/secrets/username
- /vault/secrets/password
- /vault/secrets/apikey
| Condition | UI result |
|---|---|
| Any file missing | Red background with “File(s) Not Found” |
| All files present | Green background showing Username, Password, and API Key |
- The example
index.phpoutputs a small HTML UI and reads the three files under/vault/secrets/. It suppresses warnings fromfile_get_contents()using@for this demo; in production handle errors explicitly.
- The app includes a small style block for the page layout and table formatting:
- Builds the PHP/Apache container and copies the app into the web root.
- The provided manifest creates a Deployment (replicas: 1), a NodePort Service, and a ServiceAccount named
app. The container image referenced isphp:vault(the image you built locally above).
- The repository includes
patch-annotations-template.yamlto add Vault Agent Injector annotations to the Deployment. Apply the base manifest first, then patch the deployment with the annotations so Vault can inject the secrets.
- Apply the manifest and patch the Deployment:
- Confirm the pods, services, and service accounts exist:
- The php Service is exposed as a NodePort. Use the node (VM) public IP and NodePort to open the app in your browser:
- Behavior:
- If Vault has not injected the three files at
/vault/secrets/, the UI shows a red background with “File(s) Not Found”. - Once Vault Agent Injector mounts/writes the secrets into
/vault/secrets/inside the pod, the UI will switch to green and display the username, password, and API key.
- If Vault has not injected the three files at
- Inspect the pod filesystem to validate whether the secret files exist:
- If files are missing, the UI remains in the red “File(s) Not Found” state. After successful injection, the UI displays secrets (as shown in index.php).
- The demo uses the PHP
@operator to suppress file warnings; prefer explicit error handling in production. - Use
htmlspecialchars()(as done here) or other sanitization to avoid HTML injection when rendering secrets in a browser. For production, avoid rendering raw secrets in UI and use secure secrets handling patterns.
Make sure the mount path used by your Vault injection configuration matches the file paths the application expects (here: /vault/secrets/username, /vault/secrets/password, /vault/secrets/apikey). Also confirm the ServiceAccount used by the Deployment has the necessary annotations and role bindings for Vault Agent Injector to work.
- Configure and review the Vault Agent Injector annotations in the patch file to write secrets into the pod filesystem.
- Consider using environment variables or in-memory secret stores instead of writing secrets to disk for stronger security.
- Useful links:
- HashiCorp Vault: https://www.vaultproject.io/
- Vault Kubernetes integration: https://www.vaultproject.io/docs/platform/k8s
- Kubernetes documentation: https://kubernetes.io/docs/