apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  labels:
    service: redis
spec:
  serviceName: redis
  replicas: 1
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
        service: redis
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: service
                    operator: In
                    values:
                      - redis
              topologyKey: 'kubernetes.io/hostname'
      containers:
        - name: redis-server
          image: redis
          imagePullPolicy: Always
          command:
            - redis-server
          args:
            - /etc/redis/redis.conf
            - --protected-mode
            - 'no'
          ports:
            - name: redis
              containerPort: 6379
          resources:
            requests:
              cpu: '500m'
              memory: '36Gi'
            limits:
              cpu: 1
              memory: '36Gi'
          volumeMounts:
            - mountPath: /data
              name: redis-data
            - mountPath: /etc/redis
              name: config
      nodeSelector:
        cloud.google.com/gke-nodepool: redis
      volumes:
        - name: config
          configMap:
            name: redis-config
            items:
              - key: redis.conf
                path: redis.conf
  volumeClaimTemplates:
    - metadata:
        name: redis-data
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: standard
        resources:
          requests:
            storage: 100Gi
