Migrate Consul to Raft storage
This procedure assumes you have a Vault cluster deployed in a Kubernetes environment configured with Consul storage. The storage migration can occur while leaving the Consul cluster intact. A single change to the Consul cluster is a lock file written by Vault during the migration.
This guide uses basic examples and default Vault configurations. It is for illustrative purposes, and adaption to specific configurations relevant to your environment is still required.
Back up data
Always back up your data before attempting migration! Although this is an offline operation and the risk is low, it is advisable to take a recent snapshot from your Consul cluster before proceeding.
Overview
This guide uses an intermediate Helm configuration to introduce an init container that will perform the storage migration, and then start a single Vault server using the Raft storage backend to verify the results. Then update the Helm configuration to remove the init container and start Vault replicas.
Vault and Kubernetes setup
Consider the following vault status
output and Helm Chart values for Vault:
Helm chart values:
Migration procedure
Uninstall Vault via Helm.
Deployed
StatefulSets
cannot have certain attributes modified after their initial deployment. Therefore, theStatefulSet
deployment must be entirely replaced.Vault servers using Consul storage are by default stateless. Unless explicitly configured, the Vault server
StatefulSet
does not create any Persistent Volume Claims (PVC) or other artifacts. Vault's index holds its state, which is entirely stored in the Consul serverStatefulSet
's persistent volumes.Caution
It is strongly advised to review your Vault deployment configurations and take appropriate backups for any stateful information managed via Helm or other orchestration platforms.
Create a
ConfigMap
containing the Storage Migration configuration.Often your Vault server should communicate to Consul via a Consul client agent. This example uses the service endpoint for a Consul server deployed in Kubernetes, although it can work for a Consul server cluster deployed outside of Kubernetes as well.
Apply the
ConfigMap
.Install Vault via Helm deployment with Raft Migration storage configuration.
Configuration notes
storage “raft”
configuration to specify the path for the Raft DB (/vault/data
by default), and anyretry_join
parameters in your original configuration.- This example uses
auto_join
to automatically find Raft peers via the Kubernetes API. See theretry_join
for more information.
- This example uses
dataStorage
configuration in the Helm override values, to specify the parameters of the PVCs the VaultStatefulSet
will create.extraInitContainers
will start an init container mounting the storage migration ConfigMap anddata
volume, which it will then use to execute the storage migration.replicas: 1
- This setting is temporary for the purposes of the migration. A new Vault
StatefulSet
with one replica to confirm the init container completed the migration and unseal Vault using the new storage backend.
- This setting is temporary for the purposes of the migration. A new Vault
Apply this configuration.
Review the migration logs.
Unseal Vault.
Update Vault Helm deployment with Raft storage configuration.
Configuration notes
replicas: 5
- Upgrade the Helm deployment in place using the final Raft storage configuration, removing the
extraInitContainer
and storage migrationConfigMap
, and increasing the number of replicas. Theretry_join
parameters used by the new Vault server replicas to automatically join the cluster.
- Upgrade the Helm deployment in place using the final Raft storage configuration, removing the
Apply the configuration.
Unseal Vault.
Confirm the Raft peers have formed a quorum.
Rollback procedure
To revert to the original configuration, you'll just need to delete the Helm deployment, and re-deploy it using the override values specifying your Consul storage configuration.
Note that the Vault Helm Chart's default configuration using Raft storage will retain any PVCs created. Vault does not use these while configured with Consul storage. You will need to remove the PVCs before re-attempting the migration.
Uninstall Vault via Helm.
Install Vault via Helm with old Consul storage configuration.
Unseal Vault and confirm the storage has reverted to Consul.