apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
  serviceName: wordpress
  replicas: 1
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      initContainers:
      - name: init-wordpress
        image: busybox
        command:
        - sh
        - "-c"
        - "wget -O /driver/db.php https://raw.githubusercontent.com/aaemnnosttv/wp-sqlite-db/master/src/db.php"
        volumeMounts:
        - name: dbdriver
          mountPath: /driver
      containers:
      - name: wordpress
        image: wordpress:fpm-alpine
        ports:
        - name: php-fpm
          containerPort: 9000
        volumeMounts:
        - name: dbdriver
          mountPath: /usr/src/wordpress/wp-content/db.php 
          subPath: db.php
        - name: configmap
          mountPath: /var/www/wp-config.php
          subPath: wp-config.php
        - name: database
          mountPath: /var/www/db
        - name: html
          mountPath: /var/www/html
      - name: nginx
        image: nginx:1.18-alpine
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
        - name: configmap
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: default.conf 
        - name: html
          mountPath: /var/www/html    
      volumes:
      - name: dbdriver
        emptyDir: {}
      - name: configmap
        configMap:
          name: wordpress
  volumeClaimTemplates:
  - metadata:
      name: database
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 100Mi
  - metadata:
      name: html
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 500Mi
