apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: openslice
  labels:
    org.etsi.osl.service: mysql
  name: mysql
spec:
  selector:
    matchLabels:
      org.etsi.osl.service: mysql
  serviceName: mysql
  replicas: 1
  template:
    metadata:
      labels:
        org.etsi.osl.service: mysql
    spec:
      containers:
        - env:
            - name: MYSQL_ROOT_HOST
              value: "%"
            - name: MYSQL_ROOT_PASSWORD
              value: letmein
            - name: MYSQL_DATABASE
              value: osdb
            - name: MYSQL_USER
              value: portaluser
            - name: MYSQL_PASSWORD
              value: "12345"
          image: mysql:5.7.43
          name: mysql
          ports:
            - containerPort: 3306
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: mysql-portal-claim0
            - mountPath: /docker-entrypoint-initdb.d
              name: mysql-initdb
          readinessProbe:
            exec:
              # Check we can execute queries over TCP (skip-networking is off).
              command: ["mysql", "-h", "127.0.0.1", "-u", "root",  "-pletmein", "-e", "SELECT 1"]
            initialDelaySeconds: 5
            periodSeconds: 2
            timeoutSeconds: 1
      restartPolicy: Always
      volumes:
        - name: mysql-portal-claim0
          persistentVolumeClaim:
            claimName: mysql-portal-claim0
        - name: mysql-initdb
          configMap:
            name: mysql-initdb-config
---
apiVersion: v1
kind: Service
metadata:
  namespace: openslice
  labels:
    org.etsi.osl.service: mysql
  name: mysql
spec:
  ports:
    - name: mysql
      port: 3306
      targetPort: 3306
  selector:
    org.etsi.osl.service: mysql
