Module 8: Secrets
Introduction
Shh...secrets... In the previous modules, we hardcoded our database secrets via environment variables or the secrets within the manifest YAML files. We need to encode these into base64 format before we can use them as a secret.
Create your Secrets file
- Create a secrets.yml file
- Enter in the following manifest
apiVersion: v1
kind: Secret
metadata:
name: mysql-db-password
type: Opaque
data:
db-password: <base64encodedpwhere>
- Update the mysql deployment to pull the secret
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-db-password
key: db-password
- Update the web app deployment so that it is correct and identical in both places
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-db-password
key: db-password
- Create the deployment
kubectl apply -f demo/ - Everything should create, then run
kubectl get pods kubectl logs -f podname- Access via the service IP and then make your changes and then test similar to the previous module.
Clean Up
- Run
kubectl delete -f demo/