apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8sdemo-backend-deployment
  labels:
    app: k8sdemo-backend
spec:
  selector:
    matchLabels:
      app: k8sdemo-backend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: k8sdemo-backend
    spec:
      containers:
        - image: k8sdemo-backend
          name: k8sdemo-backend-container
          imagePullPolicy: Never
          env:
            - name: MYSQL_USER_NAME
              valueFrom:
                secretKeyRef:
                  name: k8sdemo-secret
                  key: MYSQL_USER_NAME
            - name: MYSQL_USER_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: k8sdemo-secret
                  key: MYSQL_USER_PASSWORD
            - name: MYSQL_HOST
              valueFrom:
               configMapKeyRef:
                 name: k8sdemo-config
                 key: MYSQL_HOST
            - name: MYSQL_PORT
              valueFrom:
                configMapKeyRef:
                  name: k8sdemo-config
                  key: MYSQL_PORT
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: k8sdemo-config
                  key: MYSQL_DATABASE
          ports:
            - containerPort: 80
              name: portname
          volumeMounts:
            - name: k8sdemo-backend-persistentstorage
              mountPath: /app/logs
      volumes:
        - name: k8sdemo-backend-persistentstorage
          persistentVolumeClaim:
            claimName: k8sdemo-backend-pvclaim
