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.apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 2 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: nginx ports: - containerPort: 80Change to the directory that contains the
app-deployment.yamland apply the deployment.kubectl apply -f app-deployment.yamlThe output is similar to:
deployment.apps/my-app createdVerify that the application is deployed.
kubectl get podsIt might takes a couple of minutes for Pods to be in a
Runningstatus. The output is similar to:NAME READY STATUS RESTARTS AGE my-app-86d5bc587d-g85bz 1/1 Running 0 7s my-app-86d5bc587d-j4x4p 1/1 Running 0 7sCreate a service to expose the application.
kubectl expose deployment my-app --type=NodePort --port=80Find the port on which the application is running.
kubectl get svc my-appThe output is similar to:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE my-app NodePort 10.96.114.36 <none> 80:32696/TCP 8sPort forward the application to access the application in your browser.
kubectl port-forward svc/my-app 8080:80Access 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.yamland 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_PASSWORDIn 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?