apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: demo
  labels:
    app: jee
spec:
  replicas: 1
  selector:
    matchLabels:
      component: mysql
  template:
    metadata:
      labels:
        app: jee
        component: mysql
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
        - name: mysql-storage
          persistentVolumeClaim:
            claimName: mysql-data
      containers:
        - name: mysql
          image: mysql:8
          resources:
            requests:
              memory: "500Mi"
              cpu: "200m"
            limits:
              memory: "1Gi"
              cpu: "400m"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3306
              protocol: TCP
              name: mysql
          volumeMounts:
            - name: mysql-storage
              mountPath: /var/lib/mysql
          env:
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: mysql-admin
                  key: username
            - name: MYSQL_DB
              valueFrom:
                secretKeyRef:
                  name: mysql-admin
                  key: database
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-admin
                  key: password
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-admin
                  key: password
