apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: voting-app-prd
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: redis
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: name
                operator: In
                values:
                - db
            topologyKey: "kubernetes.io/hostname"
      containers:
        - env:
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: database-password
                  name: redis
          image: redis:alpine
          imagePullPolicy: IfNotPresent
          livenessProbe:
            tcpSocket:
              port: redis
            initialDelaySeconds: 15
            periodSeconds: 20
          name: redis
          ports:
            - containerPort: 6379
              name: redis
              protocol: TCP
          readinessProbe:
            tcpSocket:
              port: redis
            initialDelaySeconds: 5
            periodSeconds: 20
          securityContext:
            capabilities: {}
            privileged: false
          volumeMounts:
            - mountPath: /data
              name: redis-data
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
        - name: redis-data
          persistentVolumeClaim:
            claimName: redis
