In this guide, you’ll learn how to enable and use the Key-Value (KV) version 2 secrets engine in HashiCorp Vault. The KV secrets engine allows you to securely store arbitrary secrets—like database credentials, API keys, or certificates—and manage multiple versions, metadata, and lifecycle operations.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Vault CLI installed and configured
- A running and unsealed Vault server
- Vault Authentication set up for your environment
Ensure your Vault server is unsealed and your CLI is authenticated (
vault login) before proceeding.1. Enable the KV v2 Secrets Engine
Mount the KV v2 engine at thecrds/ path:
2. Read from an Empty Path
If no data exists atcrds/mysql, Vault returns an error:
3. Storing Secrets
3.1 Create the First Version
Store only a username:3.2 Update with a Password
Add a password to create version 2:3.3 Add an API Key
You can append fields anytime (creates version 3):4. Retrieve Secrets and Metadata
| Operation | Command | Description |
|---|---|---|
| Fetch data & metadata | vault kv get crds/mysql | Shows both secret values and metadata |
| Fetch only metadata | vault kv metadata get crds/mysql | Displays metadata and version history |
4.1 Fetch Both Data and Metadata
4.2 Fetch Only Metadata
5. Deleting Secrets
5.1 Soft Delete Latest Version
Soft-deleted versions can be undeleted until permanently destroyed. To irreversibly remove versions, use
vault kv destroy.6. Using KV Engine Inside Kubernetes
If Vault is running in Kubernetes, exec into the pod to run the same commands:After adding secrets, configure authentication methods and attach policies so applications can securely access your KV paths. See Vault Policies for more details.