Skip to main content

πŸ“˜ 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


πŸš€ Setup Walkthrough

1. πŸ“¦ Install External Secrets Operator

Validate installation:

2. πŸ” Vault Configuration (dev mode)

All commands assume execution inside the Vault pod or with the Vault CLI set up locally.
Create policy: vault/policy.hcl
Apply policy and create role:
Create test secrets:

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:
Expected Output:

πŸ“Ž Notes & Recommendations

  • Security: This guide uses Vault in dev mode 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)

Store the unseal keys and root token securely. Unseal the Vault manually or automate using auto-unseal with KMS (e.g., AWS KMS, Azure Key Vault, etc.) for production.

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.

For HA or production-grade deployments, configure Vault auto-unseal via:
  • AWS KMS
  • Azure Key Vault
  • Google Cloud KMS
This avoids needing manual unseals on every restart.

πŸ“¦ Validate PVC Attachment

Check that a PVC is bound:

🧠 Summary