Skip to main content
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.

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 the crds/ path:

2. Read from an Empty Path

If no data exists at crds/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

4.1 Fetch Both Data and Metadata

4.2 Fetch Only Metadata

5. Deleting Secrets

5.1 Soft Delete Latest Version

Reading now shows the deleted version’s metadata:
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.

Watch Video