HashiCorp Vault
Vault runs on the storage node (https://192.168.56.20:8200, also https://vault.lab.internal:8200) as a systemd service, outside the Kubernetes cluster, so secrets survive cluster rebuilds. It serves HTTPS with a certificate from its own CA. During provisioning, k8s-provisioner:
- Initializes Vault (5 unseal keys, threshold 3) and unseals it
- Saves the init data to
/etc/vault.d/vault-init.jsonon the storage node (backup:/etc/k8s-provisioner/vault-init.jsonon the controlplane) - Enables the KV v2 secrets engine and stores everything under
secret/k8s-provisioner/ - Configures the Kubernetes auth method so pods can authenticate with their ServiceAccount
- Generates random passwords for every login, and stores the API keys if configured
- Installs the Vault Secrets Operator (VSO), which mirrors each login into its Kubernetes Secret
What Vault manages
Each login has its own path with plain keys, so the Vault UI shows a clean login and password, and a Kubernetes Secret gets only the login it needs:
Secret path (secret/…) | Keys | Used by |
|---|---|---|
k8s-provisioner/grafana/admin | username, password | Grafana local admin |
k8s-provisioner/keycloak/admin | username, password | Keycloak admin console |
k8s-provisioner/keycloak/postgres | username, password | PostgreSQL (Keycloak DB) |
k8s-provisioner/keycloak/users/k8sadmin | username, password | Realm user k8sadmin (cluster-admin) |
k8s-provisioner/keycloak/users/developer | username, password | Realm user developer (view) |
k8s-provisioner/keycloak/clients/grafana | client_id, client_secret | Grafana OAuth2 client |
k8s-provisioner/api-keys | ollama_api_key, karpor_auth_token, alertmanager_config | API keys and optional overrides |
k8s-provisioner/kubeconfig-oidc | config | Ready-made OIDC kubeconfig |
Upgrading from a version that kept every login as a prefixed key in
api-keys(keycloak_k8sadmin_password, …)? The next provisioning moves each value to its path above, keeping the same passwords, and removes the old keys.
Secrets flow
config.yaml / env vars (first run only)
└─► Vault stores them
├─► grafana/admin, keycloak/{admin,postgres,users/*,clients/grafana}
│ (one path per login; passwords randomly generated)
└─► api-keys: ollama_api_key, karpor_auth_token
VSO ─────────► mirrors each login path into its K8s Secret
└─► grafana-admin, grafana-oidc, keycloak-admin, postgres-credentials
└─► pods use secretKeyRef
Ollama ──────► reads ollama_api_key from Vault → K8s Secret ollama-api-key
Karpor ──────► reads karpor_auth_token from Vault → passed to Helm (no file on disk)
After the first deploy, secrets live only in Vault: leave the API key fields in config.yaml empty.
Root token and unseal keys
vagrant ssh storage -c 'sudo cat /etc/vault.d/vault-init.json' | jq . # primary
vagrant ssh controlplane -c 'sudo cat /etc/k8s-provisioner/vault-init.json' | jq . # backup
vagrant ssh controlplane -c 'sudo k8s-provisioner vault token' # root token only
Trusting the Vault CA
Vault’s CA is generated on the storage node on the first vagrant up (/etc/vault.d/tls/ca.crt) and kept across re-provisioning. It is separate from the lab CA because Vault starts before the cluster (and cert-manager) exists. vagrant up exports it as vagrant/certs/k8s-lab-vault-ca.crt; trust it with the lab CA in Host Setup.
If you prefer not to trust it system-wide, point the CLIs at the file: export VAULT_CACERT=$PWD/certs/k8s-lab-vault-ca.crt (honored by both vault and k8s-provisioner).
Inside the lab nothing is manual: the CA is fetched to /etc/k8s-provisioner/vault-ca.crt on the controlplane, VSO gets it as the vault-ca Secret, and on the storage node VAULT_ADDR/VAULT_CACERT are preset for login shells (/etc/profile.d/vault.sh).
UI
Open https://vault.lab.internal:8200 and log in with the root token. The UI’s Copy buttons use the browser clipboard API, which only works on HTTPS pages with a trusted certificate.
CLI
export VAULT_ADDR=https://192.168.56.20:8200 # needs the Vault CA trusted, or VAULT_CACERT
export VAULT_TOKEN=$(vagrant ssh storage -c 'sudo cat /etc/vault.d/vault-init.json' | jq -r .root_token)
# List and read
vault kv list secret/k8s-provisioner/
vault kv get secret/k8s-provisioner/keycloak/users/k8sadmin
vault kv get -field=password secret/k8s-provisioner/grafana/admin
# Add a key (keeps the others) / replace a path / new path
vault kv patch secret/k8s-provisioner/api-keys my_secret="value"
vault kv put secret/my-app/config db_password="strong-password"
# Versions
vault kv metadata get secret/k8s-provisioner/api-keys
vault kv get -version=1 secret/k8s-provisioner/api-keys
vault kv undelete -versions=1 secret/k8s-provisioner/api-keys
Or with the project CLI: k8s-provisioner vault get|set|status|unseal (see CLI Reference).
Policies and Kubernetes auth
vault policy read k8s-provisioner
vault policy write my-app - <<EOF
path "secret/data/my-app/*" {
capabilities = ["read"]
}
EOF
vault read auth/kubernetes/role/k8s-provisioner
vault write auth/kubernetes/role/my-app \
bound_service_account_names="my-app-sa" \
bound_service_account_namespaces="default" \
policies="my-app" \
ttl="1h"
Example app
kubectl apply -f examples/vault-secret-app.yaml # init container logs in with its ServiceAccount
kubectl logs -l app=vault-demo -c vault-fetch-secrets
kubectl exec -it deploy/vault-demo-app -- cat /vault/secrets/grafana-admin.json
kubectl delete -f examples/vault-secret-app.yaml
Rotating a password
# VSO updates the grafana-admin Secret within 30s
vault kv patch secret/k8s-provisioner/grafana/admin password="new-strong-password"
kubectl rollout restart deployment/grafana -n monitoring
Unsealing after a reboot
Vault seals itself when the storage node restarts. Unseal it with the project CLI on the controlplane, or by hand:
vagrant ssh controlplane -c 'sudo k8s-provisioner vault unseal'
# or, on the storage node, with 3 of the 5 keys from vault-init.json
vagrant ssh storage
vault operator unseal <key-1>
vault operator unseal <key-2>
vault operator unseal <key-3>
Best practices
| Practice | Why |
|---|---|
Never commit config.yaml with keys filled in (use env vars) | Avoids accidental exposure in git |
| Use Vault as the single source of truth after the first deploy | Traceability and centralized rotation |
| One least-privilege policy per application | A leaked secret does not expose the others |
Use kv patch to update without overwriting other keys | Keeps the KV v2 version history |
| Never use the root token in applications | Create scoped tokens: vault token create -policy=my-app |
Disabling Vault
vault:
enabled: false
There are no default passwords then: Grafana and Keycloak credentials are generated randomly and written to /etc/k8s-provisioner/grafana-credentials.txt and /etc/k8s-provisioner/keycloak-credentials.txt (mode 0600) on the controlplane, and API keys come straight from config.yaml or the environment.