apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
spec:
  selector:
    matchLabels:
      service: redis
  replicas: 1
  serviceName: redis
  template:
    metadata:
      labels:
        service: redis
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: kubernetes.io/os
                  operator: In
                  values:
                    - linux
                - key: node-role.kubernetes.io/worker
                  operator: In
                  values:
                    - worker
                - key: type
                  operator: In
                  values:
                    - on-premise
                - key: provider
                  operator: In
                  values:
                    - host
                - key: service
                  operator: In
                  values:
                    - virtualbox
                - key: region
                  operator: In
                  values:
                    - local
                - key: availability_zone
                  operator: In
                  values:
                    - local-c
      containers:
        - name: main
          image: sloopstash/redis:v1
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: supervisor-server
              mountPath: /etc/supervisord.conf
              subPath: supervisor-server
            - name: redis-supervisor
              mountPath: /etc/supervisord.d/redis.ini
              subPath: redis-supervisor
            - name: redis-server
              mountPath: /opt/redis/conf/redis.conf
              subPath: redis-server
            - name: redis-data
              mountPath: /opt/redis/data
            - name: redis-log
              mountPath: /opt/redis/log
          command:
            - "/usr/bin/supervisord"
            - "-c"
            - "/etc/supervisord.conf"
          ports:
            - containerPort: 6379
          readinessProbe:
            tcpSocket:
              port: 6379
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            exec:
              command:
                - "/usr/local/bin/redis-cli"
                - "PING"
            initialDelaySeconds: 15
            periodSeconds: 20
        - name: log
          image: sloopstash/redis:v1
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: supervisor-server
              mountPath: /etc/supervisord.conf
              subPath: supervisor-server
            - name: redis-log
              mountPath: /opt/redis/log
          command:
            - "/usr/bin/supervisord"
            - "-c"
            - "/etc/supervisord.conf"
      volumes:
        - name: supervisor-server
          configMap:
            name: redis
        - name: redis-supervisor
          configMap:
            name: redis
        - name: redis-server
          configMap:
            name: redis
        - name: redis-data
          persistentVolumeClaim:
            claimName: redis-data
        - name: redis-log
          persistentVolumeClaim:
            claimName: redis-log
  volumeClaimTemplates:
    - metadata:
        name: redis-data
      spec:
        storageClassName: redis-data
        volumeMode: Filesystem
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 2Gi
    - metadata:
        name: redis-log
      spec:
        storageClassName: redis-log
        volumeMode: Filesystem
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
