kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: standard
  labels:
    app: redis
  annotations:
    storageclass.beta.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
  fsType: ext4
allowVolumeExpansion: true
reclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-data
  labels:
    app: redis
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  labels:
    app: redis
spec:
  selector:
    matchLabels:
      app: redis
  serviceName: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      initContainers:
        - name: init-sysctl
          image: busybox
          command:
            - /bin/sh
            - -c
            - |
              sysctl -w net.core.somaxconn=1024;
              echo never > /sys/kernel/mm/transparent_hugepage/enabled
          securityContext:
            privileged: true
          volumeMounts:
            - name: host-sys
              mountPath: /sys
      containers:
        - image: cr.seqera.io/public/redis:5.0.8
          name: redis
          args:
            - --appendonly yes
          ports:
            - containerPort: 6379
          volumeMounts:
            - mountPath: "/data"
              name: "vol-data"
      volumes:
        - name: vol-data
          persistentVolumeClaim:
            claimName: redis-data
        - name: host-sys
          hostPath:
            path: /sys
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    app: redis
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: redis
