π Vault + External Secrets Operator (ESO) + ENV Injection Demo
This documentation provides a step-by-step integration of HashiCorp Vault with External Secrets Operator (ESO) to securely inject secrets as environment variables into Kubernetes Pods. This setup ensures security best practices for managing application secrets at runtime.π Project Structure
π§ Prerequisites
| Component | Required |
|---|---|
| Kubernetes Cluster | β |
| Helm CLI | β |
| HashiCorp Vault (dev mode ok) | β |
| External Secrets Operator | β |
π Setup Walkthrough
1. π¦ Install External Secrets Operator
2. π Vault Configuration (dev mode)
All commands assume execution inside the Vault pod or with the Vault CLI set up locally.
vault/policy.hcl
3. βοΈ Kubernetes Resource Setup
Apply all manifests in sequence:β Breakdown of Key Resources
00-namespace.yaml
01-serviceaccount.yaml
02-secretstore.yaml
03-externalsecret.yaml
04-nginx-deployment.yaml
β Validation
Once the pod is up and running, verify that secrets have been correctly injected as environment variables:π Notes & Recommendations
- Security: This guide uses Vault in
devmode and HTTPβnot recommended for production. Use TLS and HA mode in production environments. - Policy Design: Keep policies granular and service-account specific to follow the principle of least privilege.
- Refresh Behavior: ExternalSecrets will update Kubernetes secrets every hour (as per
refreshInterval), ensuring changes in Vault propagate automatically.
Setup Vault in PROD persistent mode
To preserve Vault data across pod restarts or deletions, you need to move away from using Vault in dev mode, because:β Vault in dev mode stores all data in-memory, so all secrets are lost when the pod is deleted or restarted.
β Solution: Use Vault in Production Mode with Persistent Storage
Hereβs how you can update your setup so Vault retains secrets after pod restarts:π Step-by-Step Setup for Persistent Vault
1. Install Vault via Helm with Persistent Storage
Use the official HashiCorp Vault Helm chart and enable persistent storage.Add the repo and install:
Create a vault-values.yaml with persistence enabled:
Install Vault:
2. Initialize & Unseal Vault (only once)
3. Port Forward and Login to Vault
4. Continue with Your Existing Setup
Once youβre using persistent Vault, the rest of your ESO integration stays mostly the same:- Kubernetes auth config
- Secret paths like
secret/data/myapp/env - ESOβs
SecretStore,ExternalSecret, etc.
β Now, even if the Vault pod restarts or is rescheduled, the secrets and configs will persist via the PVC.
π Optional: Auto-Unseal Setup (Recommended for Production)
For HA or production-grade deployments, configure Vault auto-unseal via:- AWS KMS
- Azure Key Vault
- Google Cloud KMS
π¦ Validate PVC Attachment
Check that a PVC is bound:π§ Summary
| Setup Part | Dev Mode | Production Mode (Recommended) |
|---|---|---|
| Secrets persistence | β Lost on restart | β Persisted with PVC |
| Security | β Minimal (no TLS) | β Can be hardened |
| Use for demos | β Yes | β Yes (better choice) |
| Real-world readiness | β No | β Yes |
