apiVersion: apps/v1
kind: Deployment
metadata:
  name: guacamole-db
  namespace: guacamole
  labels:
    app: guacamole
    tier: backend
spec:
  selector:
    matchLabels:
      app: guacamole
      tier: backend
  template:
    metadata:
      labels:
        app: guacamole
        tier: backend
    spec:
      containers:
        - name: guacamole-db
          image: mariadb:10.5.3
          imagePullPolicy: IfNotPresent
          lifecycle:
            postStart:
              exec:
                command: ["/bin/sh", "-c", /opt/poststart.sh]
          env:
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: guacamole
                  key: user_login
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: guacamole
                  key: user_password
            - name: MYSQL_DATABASE
              valueFrom:
                secretKeyRef:
                  name: guacamole
                  key: database
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: guacamole
                  key: mysql_root_password
          ports:
            - name: guacamole-db
              containerPort: 3306
          livenessProbe:
            tcpSocket:
              port: 3306
            initialDelaySeconds: 25
            periodSeconds: 25
          resources:
            requests:
              memory: "64Mi"
              cpu: "250m"
            limits:
              memory: "128Mi"
              cpu: "500m"
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: "/var/lib/mysql"
            - name: hookvolume
              mountPath: /opt/poststart.sh
              subPath: poststart.sh
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: sqldb-storage
        - name: hookvolume
          configMap:
            name: poststarthook
            defaultMode: 0755
