apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rd
spec:
  serviceName: "redis"
  replicas: 3
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      initContainers:
      - name: install
        image: gcr.io/kubernetes-e2e-test-images/pets/redis-installer:1.2
        imagePullPolicy: Always
        args:
        - "--install-into=/opt"
        - "--work-dir=/work-dir"
        volumeMounts:
        - name: opt
          mountPath: "/opt"
        - name: workdir
          mountPath: "/work-dir"
      - name: bootstrap
        image: debian:jessie
        command:
        - "/work-dir/peer-finder"
        args:
        - -on-start="/work-dir/on-start.sh"
        - "-service=redis"
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        volumeMounts:
        - name: opt
          mountPath: "/opt"
        - name: workdir
          mountPath: "/work-dir"
      containers:
      - name: redis
        image: debian:jessie
        ports:
        - containerPort: 6379
          name: peer
        command:
        - /opt/redis/redis-server
        args:
        - /opt/redis/redis.conf
        readinessProbe:
          exec:
            command:
            - sh
            - -c
            - "/opt/redis/redis-cli -h $(hostname) ping"
          initialDelaySeconds: 15
          timeoutSeconds: 5
        volumeMounts:
        - name: datadir
          mountPath: /data
        - name: opt
          mountPath: /opt
      volumes:
      - name: opt
        emptyDir: {}
      - name: workdir
        emptyDir: {}
  volumeClaimTemplates:
  - metadata:
      name: datadir
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
