Vault + External Secrets Operator
This guide covers deploying HashiCorp Vault as a central secret store and External Secrets Operator (ESO) to sync secrets into Kubernetes automatically.
Architecture
[Vault] namespace: vault
│ Kubernetes auth method (ServiceAccount token exchange)
▼
[ESO ClusterSecretStore] — cluster-wide, references Vault KV v2
│ ExternalSecret CRs per namespace
▼
[Kubernetes Secrets] — consumed natively by pods / Helm chartsStorage: Vault uses Raft integrated storage backed by a local-path PVC — no external Consul or etcd required.
Auth: ESO authenticates to Vault via the Kubernetes auth method. ESO's own ServiceAccount token is exchanged for a scoped Vault token at sync time.
UI access: the chart exposes no ingress: the UI is the vault ClusterIP service. Use kubectl -n vault port-forward svc/vault 8200 and open https://localhost:8200, or publish it yourself from your config repo (behind a VPN or an IP allow-list, preferably).
Secret path layout
| Vault path | Kubernetes Secret | Namespace |
|---|---|---|
secret/argocd/oidc | argocd-secret | argocd |
secret/grafana/admin | grafana-admin-secret | monitoring |
secret/grafana/oauth | grafana-oauth-secret | monitoring |
secret/traefik/dashboard | traefik-dashboard-auth | ingress |
Prerequisites
Add to .env:
VAULT_DOMAIN=vault.example.comAdd DNS A record: vault.example.com → SERVER_IP
Step 1 — Deploy Vault
First, the vault-tls secret. The listener terminates TLS itself and the chart mounts the vault-tls secret unconditionally: without it the pod never starts. Create it in the vault namespace before installing, with a cert-manager Certificate (see cert-manager) or by hand.
Then deploy the platform-vault OCI chart, via ArgoCD or directly with Helm:
helm upgrade --install platform-vault \
oci://ghcr.io/kevindebenedetti/charts/platform-vault \
--version <k3s-lab release, e.g. 0.25.0> \
--namespace vault --create-namespace \
--values <your config repo>/platform/vault/values.yaml # optional overridesThis installs Vault into the vault namespace (StatefulSet vault, pod vault-0, the defaults of the task vault:* scripts) with:
- Single-replica Raft storage (5 Gi PVC on
local-path) - TLS on the listener (
:8200), from thevault-tlssecret - The UI as a
ClusterIPservice only: the chart ships no ingress. Reach it withkubectl -n vault port-forward svc/vault 8200, or expose it deliberately from your config repo.
See the chart README for the full topology.
⚠️ Vault starts sealed and uninitialized — proceed to Step 2.
Step 2 — Initialize Vault
task vault:initThis script:
- Calls
vault operator init(3 key shares, threshold 2:VAULT_KEY_SHARESandVAULT_KEY_THRESHOLD) - Unseals Vault with the generated keys, stopping at the threshold
- Runs the configure steps — the same ones
task vault:configurere-applies at any time:- enables KV v2 at
secret/ - enables and configures Kubernetes auth
- writes every
*.hclfile of the policy directory as a policy named after the file - creates the
esorole (policyeso-read) - sets up OIDC login (policy
vault-admin) whenOIDC_CLIENT_ID,OIDC_CLIENT_SECRET,OIDC_ISSUER_URL,VAULT_DOMAINandADMIN_EMAILare all set; with only some of them it stops before changing anything
- enables KV v2 at
On an already initialised Vault it skips step 1, unseals if needed, and configures. All of it lives in lib/vault.sh; see Configuration for every variable.
Policies
The shipped policies are in vault/policies/: eso-read lets External Secrets read all of secret/, and vault-admin is the OIDC administrator. To narrow them, copy the directory into your config repo, edit it, and set VAULT_POLICY_DIR to the copy. Every *.hcl file there becomes a policy, so you can add your own. configure refuses a directory without eso-read.hcl, and without vault-admin.hcl when OIDC is on.
Output:
════════════════════════════════════════════════════════════════
⚠️ VAULT INIT OUTPUT — SAVE THIS IMMEDIATELY
These keys and token will NEVER be shown again.
════════════════════════════════════════════════════════════════
Unseal Key 1: abc123...
Unseal Key 2: def456...
Unseal Key 3: ghi789...
Root Token: hvs.XXXXX📋 Store these in a password manager immediately. You will need 2 of the 3 unseal keys any time the Vault pod restarts (e.g., after a node reboot).
Add to .env for convenience (never commit):
VAULT_ROOT_TOKEN=hvs.XXXXX
VAULT_UNSEAL_KEY_1=abc123...
VAULT_UNSEAL_KEY_2=def456...Step 3 — Seed secrets into Vault
VAULT_ROOT_TOKEN=hvs.XXXXX task vault:seedIt reads its values from .env (or the environment) and writes each secret whose values are set, skipping the others with a message:
secret/argocd/oidc: OIDCclientID+clientSecret(OIDC_CLIENT_ID,OIDC_CLIENT_SECRET)secret/grafana/admin: Grafana adminusername+password(GRAFANA_PASSWORD)secret/grafana/oauth: allGF_AUTH_*OAuth settings (OIDC_CLIENT_ID,OIDC_AUTH_URL, …)secret/traefik/dashboard: the htpasswdusersstring (DASHBOARD_PASSWORD, needshtpasswd)
Step 4 — Deploy External Secrets Operator
ArgoCD deploys External Secrets Operator from Git. No manual deploy command is needed.Installs the external-secrets/external-secrets Helm chart into the external-secrets namespace.
Step 5 — Apply ClusterSecretStore + ExternalSecrets
# In your config repo:
kubectl apply -f secrets/cluster-secret-store.yaml
kubectl apply -f secrets/ESO immediately begins syncing. Check status:
task vault:statusDay 2 — Unsealing after reboot
Vault becomes sealed when the pod restarts. Unseal with:
task vault:unsealIt feeds VAULT_UNSEAL_KEY_1, VAULT_UNSEAL_KEY_2, … from .env one at a time and stops as soon as Vault reports unsealed. A key that is not set is asked for on the terminal.
Or interactively:
kubectl exec -it -n vault vault-0 -- env VAULT_SKIP_VERIFY=true vault operator unsealAudit log
Enable it once, to stdout — never to a file on a volume: an unrotated file fills the disk, and Vault then refuses every request.
kubectl exec -it -n vault vault-0 -- env VAULT_SKIP_VERIFY=true VAULT_TOKEN=<root> \
vault audit enable file file_path=stdoutAdding new secrets
Write to Vault:
bashkubectl exec -n vault vault-0 -- \ env VAULT_TOKEN="${VAULT_TOKEN:?set-from-vault-init}" VAULT_SKIP_VERIFY=true \ vault kv put secret/myapp/config \ DB_PASSWORD=secret123 \ API_KEY=key456Create an ExternalSecret manifest:
yamlapiVersion: external-secrets.io/v1 kind: ExternalSecret metadata: name: myapp-secret namespace: apps spec: refreshInterval: 1h secretStoreRef: name: vault kind: ClusterSecretStore target: name: myapp-secret creationPolicy: Owner data: - secretKey: DB_PASSWORD remoteRef: key: secret/myapp/config property: DB_PASSWORD - secretKey: API_KEY remoteRef: key: secret/myapp/config property: API_KEYApply:
kubectl apply -f myapp-externalsecret.yaml