Kubernetes service registration
Kubernetes Service Registration tags Vault pods with their current status for use with selectors. Service registration is only available when Vault is running in High Availability mode.
- HashiCorp Supported – Kubernetes Service Registration is officially supported by HashiCorp.
Configuration
Alternatively, the namespace and pod name can be set through the following environment variables:
This allows you to set these parameters using the Downward API.
If using only environment variables, the service registration stanza declaring you're using Kubernetes must still exist to indicate your intentions:
For service registration to succeed, Vault must be able to apply labels to pods in Kubernetes. The following RBAC rules are required to allow the service account associated with the Vault pods to update its own pod specification:
Examples
Once properly configured, enabling service registration will cause Kubernetes pods to come up with the following labels:
After shutdowns, Vault pods will bear the following labels:
Label definitions
vault-active
(string: "true"/"false")
– Vault active is updated dynamically each time Vault's active status changes. True indicates that this Vault pod is currently the leader. False indicates that this Vault pod is currently a standby.vault-initialized
(string: "true"/"false")
– Vault initialized is updated dynamically each time Vault's initialization status changes. True indicates that Vault is currently initialized. False indicates the Vault is currently uninitialized.vault-perf-standby
(string: "true"/"false")
– Vault performance standby is updated dynamically each time Vault's leader/standby status changes. This field is only valuable if the pod is a member of a performance standby cluster, it will simply be set to "false" when it's not applicable. True indicates that this Vault pod is currently a performance standby. False indicates that this Vault pod is currently a performance leader.vault-sealed
(string: "true"/"false")
– Vault sealed is updated dynamically each time Vault's sealed/unsealed status changes. True indicates that Vault is currently sealed. False indicates that Vault is currently unsealed.vault-version
(string: "1.18.1")
– Vault version is a string that will not change during a pod's lifecycle.
Working with vault's service discovery labels
Example service
With labels applied to the pod, services can be created using selectors to filter pods with specific Vault HA roles,
effectively allowing direct communication with subsets of Vault pods. Note the vault-active: "true"
line below.
Also, by setting publishNotReadyAddresses: false
above, pods that have failed will be removed from the service pool.
With this active service in place, we now have a dedicated endpoint that will always reach the active node. When setting up Vault replication, it can be used as the primary address:
Example upgrades
In conjunction with the pod labels and the OnDelete
upgrade strategy, upgrades are much easier to orchestrate:
When deleting an instance of a pod, the StatefulSet
defining the desired state of the cluster will reschedule the
deleted pods with the newest image.