---
apiVersion: v1
kind: Service
metadata:
  name: jackson-mariadb
  labels:
    app: mariadb
spec:
  type: ClusterIP
  ports:
    - name: mariadb
      port: 3306
      targetPort: 3306
  selector:
    app: mariadb
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: jackson-mariadb
spec:
  selector:
    matchLabels:
      app: mariadb
  serviceName: jackson-mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
        - name: mariadb
          image: mariadb:10.10.2
          imagePullPolicy: IfNotPresent
          env:
            - name: MARIADB_DATABASE
              value: mysql
            - name: MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
              value: 'yes'
          ports:
            - name: mariadb
              containerPort: 3306
          livenessProbe:
            exec:
              command:
                - mysqladmin
                - ping
            initialDelaySeconds: 30
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            exec:
              command:
                - mysqladmin
                - ping
            initialDelaySeconds: 5
            timeoutSeconds: 1
            periodSeconds: 10
          volumeMounts:
            - name: jackson-mariadb-data
              mountPath: /var/lib/mysql
      volumes:
        - name: jackson-mariadb-data
          persistentVolumeClaim:
            claimName: jackson-mariadb-data
  volumeClaimTemplates:
    - metadata:
        name: jackson-mariadb-data
      spec:
        accessModes:
          - 'ReadWriteOnce'
        resources:
          requests:
            storage: 1Gi
