Passing vHSM secrets using ConfigMaps
Learn to inject vHSM secrets using ConfigMaps to an application running in Kubernetes.
vHSM stores secrets securely, but Kubernetes applications need a way to access them. One method is using ConfigMaps. This section provides instructions to inject vHSM secrets using ConfigMaps to an application running in Kubernetes.
Prerequisites
Install kubectl
Install a Kubernetes cluster
To pass vault secrets using ConfigMaps:
Deploy a sample application
Create a deployment YAML file, named
app-deployment.yaml
.Change to the directory that contains the
app-deployment.yaml
and apply the deployment.The output is similar to:
Verify that the application is deployed.
It might takes a couple of minutes for Pods to be in a
Running
status. The output is similar to:Create a service to expose the application.
Find the port on which the application is running.
The output is similar to:
Port forward the application to access the application in your browser.
Access the application that you deployed in your browser at:
http://localhost:8080
.
Enable vHSM secrets engine and store the secret
Ensure that vHSM is running and the status is unsealed. For more information about using vHSM CLI, see the vHSM CLI documentation.
The output is similar to:
Enable KV Secrets Engine, a key-value store that contains secrets in vHSM's physical storage:
The output is similar to:
Store a secret in vHSM:
The output is similar to:
Create a ConfigMap from vHSM secrets
Retrive the password that you stored in the vHSM server.
Create a ConfigMap that would inject the secret from the vHSM.
The output is similar to:
Create a new deployment YAML file, named
app-with-configmap.yaml
.Change to the directory that contains the
app-with-configmap.yaml
and apply the deployment.The output is similar to:
Verify that the application is deployed.
The output is similar to:
Verify that secrets are passed to the newly deployed application using the command:
kubectl exec -it <pod> -- printenv | grep DB_PASSWORD
In this case the Pod that is running with the application with ConfigMap ismy-app-with-configmap-6946f8b754-hfhcn
.The output is:
This confirms that the secret for the application is injected to the application using ConfigMaps.
Last updated
Was this helpful?