Configure Vault Cluster
Step 1: Initialize and unseal one Vault pod
To start, Vault needs to be initialized and unsealed. Follow these steps:
- Initialize Vault with one key share and one key threshold:
kubectl exec -n secrets vault-0 -- vault operator init -key-shares=1 -key-threshold=1 -format=json > cluster-keys.json
- Display the unseal key found in
cluster-keys.json
:
cat cluster-keys.json | jq -r ".unseal_keys_b64[]"
- Create a variable named
VAULT_UNSEAL_KEY
to capture the Vault unseal key:
VAULT_UNSEAL_KEY=$(cat cluster-keys.json | jq -r ".unseal_keys_b64[]")
- Unseal Vault running on the
vault-0
pod:
kubectl exec -n secrets vault-0 -- vault operator unseal $VAULT_UNSEAL_KEY
Step 2: Join the other Vaults to the Vault cluster
To create a Vault HA cluster, you need to join the other Vaults to the cluster. Here's how:
- Display the root token found in
cluster-keys.json
:
cat cluster-keys.json | jq -r ".root_token"
- Create a variable named
CLUSTER_ROOT_TOKEN
to capture the Vault root token:
CLUSTER_ROOT_TOKEN=$(cat cluster-keys.json | jq -r ".root_token")
- Login with the root token on the
vault-0
pod:
kubectl exec -n secrets vault-0 -- vault login $CLUSTER_ROOT_TOKEN
- List all the nodes within the Vault cluster for the
vault-0
pod:
kubectl exec -n secrets vault-0 -- vault operator raft list-peers
- Join the Vault server on
vault-1
to the Vault cluster:
kubectl exec -n secrets vault-1 -- vault operator raft join http://vault-0.vault-internal:8200
- Unseal the Vault server on
vault-1
with the unseal key:
kubectl exec -n secrets vault-1 -- vault operator unseal $VAULT_UNSEAL_KEY
- Join the Vault server on
vault-2
to the Vault cluster:
kubectl exec -n secrets vault-2 -- vault operator raft join http://vault-0.vault-internal:8200
- Unseal the Vault server on
vault-2
with the unseal key:
kubectl exec -n secrets vault-2 -- vault operator unseal $VAULT_UNSEAL_KEY
- List all the nodes within the Vault cluster for the
vault-0
pod:
kubectl exec -n secrets vault-0 -- vault operator raft list-peers
Verify Cluster Status
To ensure the Vault cluster is properly set up, follow these steps:
- Get all the pods within the default namespace:
kubectl get pods -n secrets
- Check that the
vault-0
,vault-1
, andvault-2
pods are running and ready (1/1).