# Run MySQL as stateful application. Simple version with hostPath volume.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: database-replicaset
  labels:
    app: mysql-database
    version: "1"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-database
      version: "1"
  template:
    metadata:
      labels:
        app: mysql-database
        version: "1"
    spec:
      containers:
        - name: mysql-database
          # should use Deployment to manage versions
          image: "mysql:5.7.17"
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: data-volume
          env:
            # just for testing, should actually use secrets
            - name: MYSQL_ROOT_PASSWORD
              value: "secret"
          livenessProbe:
            tcpSocket:
              port: 3306
      volumes:
        - name: data-volume
          hostPath:
            # created this directory on host beforehand but
            # type: DirectoryOrCreate should create if it doesn't exist
            path: /var/lib/k8s-mysql
            type: DirectoryOrCreate