---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mariadb
  labels:
    service: mariadb
spec:
  serviceName: mariadb
  replicas: 3
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      service: mariadb
  template:
    metadata:
      labels:
        service: mariadb
    spec:
      containers:
        - name: mariadb
          image: docker.io/alvistack/mariadb:develop
          resources:
            requests:
              cpu: 100m
              memory: 511M
            limits:
              memory: 512M
          ports:
            - containerPort: 3306
            - containerPort: 4444
            - containerPort: 4567
            - containerPort: 4568
          env:
            - name: MYSQL_DATABASE
              value: "default"
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mariadb
                  key: MYSQL_ROOT_PASSWORD
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
          args:
            - /bin/sh
            - -c
            - peer-finder -on-start=on-start.sh -service=mariadb
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "SELECT 1"
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - mysql -uroot -p$MYSQL_ROOT_PASSWORD -e "SELECT 1"
            initialDelaySeconds: 30
          volumeMounts:
            - mountPath: /etc/mysql/mariadb.conf.d
              name: etc-mysql-mariadb-conf-d
            - mountPath: /var/lib/mysql
              name: var-lib-mysql
      volumes:
        - name: etc-mysql-mariadb-conf-d
          configMap:
            name: etc-mysql-mariadb-conf-d
  volumeClaimTemplates:
    - metadata:
        name: var-lib-mysql
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
