apiVersion: apps/v1
kind: Deployment                    # Type of the kubernetes resource
metadata:
  name: <TODO_DB_INSTANCE>           # Name of the deployment
  labels:                           # Labels applied to this deployment 
    app: <TODO_APP_NAME>
spec:
  selector:
    matchLabels:                    # This deployment applies to the Pods matching the specified labels
      app: <TODO_APP_NAME>
      tier: db
  strategy:
    type: Recreate
  template:                         # Template for the Pods in this deployment
    metadata:
      labels:                       # Labels to be applied to the Pods in this deployment
        app: <TODO_APP_NAME>
        tier: db
    spec:                           # The spec for the containers that will be run inside the Pods in this deployment
      containers:
      - image: mysql:5.7            # The container image
        name: mysql
        env:                        # Environment variables passed to the container 
        - name: MYSQL_ROOT_PASSWORD 
          valueFrom:                # Read environment variables from kubernetes secrets
            secretKeyRef:
              name: db-root-pass
              key: password
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              name: db-url
              key: database
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: db-user-pass
              key: username
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-user-pass
              key: password
        ports:
        - containerPort: 3306        # The port that the container exposes       
          name: mysql
        volumeMounts:
        - name: db-persistent-storage  # This name should match the name specified in `volumes.name`
          mountPath: /var/lib/mysql
      volumes:                       # A PersistentVolume is mounted as a volume to the Pod  
      - name: db-persistent-storage
        persistentVolumeClaim:
          claimName: db-pv-claim