Skip to main content

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


  1. Create a secrets.yml file
  2. Enter in the following manifest
apiVersion: v1
kind: Secret
metadata:
name: mysql-db-password
type: Opaque
data:
db-password: <base64encodedpwhere>
  1. Update the mysql deployment to pull the secret
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-db-password
key: db-password
  1. 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
  1. Create the deployment kubectl apply -f demo/
  2. Everything should create, then run kubectl get pods
  3. kubectl logs -f podname
  4. Access via the service IP and then make your changes and then test similar to the previous module.

Clean Up


  1. Run kubectl delete -f demo/