mariadb-server.yaml 2.37 KB
---
apiVersion: v1
kind: Service
metadata:
  name: mariadb
spec:
  selector:
    app: mariadb-server
  ports:
    - name: mysql
      protocol: TCP
      port: 3306
      targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb-server
  labels:
    app: mariadb-server
spec:
  replicas: 1
  progressDeadlineSeconds: 600
  selector:
    matchLabels:
      app: mariadb-server
  template:
    metadata:
      labels:
        app: mariadb-server
    spec:
      restartPolicy: Always
      securityContext:
        runAsUser: 0
        runAsGroup: 0

      volumes:
        - name: mariadb-data
          persistentVolumeClaim:
            claimName: mariadb-data
        - name: mariadb-entrypoint-initdb
          persistentVolumeClaim:
            claimName: mariadb-entrypoint-initdb
        - name: mariadb-scripts
          configMap:
            name: mariadb-scripts
            defaultMode: 0755
        - name: mariadb-config
          configMap:
            name: mariadb-config
        - name: mariadb-secret
          secret:
            secretName: mariadb-secret
        - name: database-restore
          emptyDir: {}

      initContainers:
        - name: wait-for-file
          image: debian
          command: ["/scripts/wait-for-file"]
          volumeMounts:
            - name: mariadb-entrypoint-initdb
              mountPath: /docker-entrypoint-initdb.d
            - name: mariadb-scripts
              mountPath: /scripts
          env:
            - name: WAIT_FOR_FILE
              value: /docker-entrypoint-initdb.d/.restored

      containers:
        - name: mariadb
          image: mariadb
          volumeMounts:
            - name: mariadb-data
              mountPath: /var/lib/mysql
            - name: mariadb-config
              mountPath: /var/mariadb-config
            - name: mariadb-secret
              mountPath: /var/mariadb-secret
            - name: mariadb-entrypoint-initdb
              mountPath: /docker-entrypoint-initdb.d
          env:
            - name: MARIADB_DATABASE_FILE
              value: /var/mariadb-config/MARIADB_DATABASE
            - name: MARIADB_USER_FILE
              value: /var/mariadb-config/MARIADB_USER
            - name: MARIADB_PASSWORD_FILE
              value: /var/mariadb-secret/MARIADB_PASSWORD
            - name: MARIADB_ROOT_PASSWORD_FILE
              value: /var/mariadb-secret/MARIADB_ROOT_PASSWORD