apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nextcloud
  name: nextcloud
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nextcloud
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nextcloud
    spec:
      containers:
        - name: cron
          image: nextcloud
          volumeMounts:
            - mountPath: /var/www/html
              name: nextcloud
              subPath: html
          command: [ "/cron.sh" ]
          resources: {}
        - image: mariadb
          name: mariadb
          args:
            - --transaction-isolation=READ-COMMITTED
            - --binlog-format=ROW
            - --innodb-file-per-table=1
            - --skip-innodb-read-only-compressed
          env:
            - name: MARIADB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nextcloud-secret
                  key: MARIADB_ROOT_PASSWORD
            - name: MYSQL_DATABASE
              value: nextcloud
            - name: MYSQL_USER
              value: nextcloud
            - name: REDIS_HOST
              value: 127.0.0.1
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nextcloud-secret
                  key: MYSQL_PASSWORD
          resources:
            limits:
              cpu: "0.2"
              memory: "2Gi"
          ports:
            - name: mariadb
              containerPort: 3306
              protocol: TCP
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: nextcloud
              subPath: db-storage
        - image: redis:alpine
          name: redis
          resources:
            limits:
              cpu: "0.1"
              memory: "2Gi"
          ports:
            - name: redis
              containerPort: 6379
              protocol: TCP
        - image: nextcloud
          name: nextcloud
          env:
            - name: MYSQL_DATABASE
              value: nextcloud
            - name: MYSQL_HOST
              value: 127.0.0.1:3306
            - name: MYSQL_USER
              value: nextcloud
            - name: PHP_MEMORY_LIMIT
              value: 2G
            - name: PHP_UPLOAD_LIMIT
              value: 100G
            - name: REDIS_HOST
              value: 127.0.0.1
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: nextcloud-secret
                  key: MYSQL_PASSWORD
          ports:
            - name: nextcloud
              containerPort: 80
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /var/www/html
              name: nextcloud
              subPath: html
            - mountPath: /var/www/html/data
              name: nextcloud-data
      restartPolicy: Always
      volumes:
        - name: nextcloud
          persistentVolumeClaim:
            claimName: nextcloud

        - name: nextcloud-data
          nfs:
            server: 192.168.178.4
            path: /mnt/storage/service/nextcloud/data
            readOnly: false