---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ service_name }}-master
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
spec:
  selector:
    matchLabels:
      app: {{ service_name }}
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ service_name }}
        role: master
        tier: backend
    spec:
      containers:
      - name: master
        image: redis:latest
        imagePullPolicy: "Always"
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  name: {{ service_name }}-master
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
    role: master
    tier: backend
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: {{ service_name }}
    role: master
    tier: backend
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ service_name }}-slave
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
spec:
  selector:
    matchLabels:
      app: {{ service_name }}
      role: slave
      tier: backend
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  replicas: 2
  template:
    metadata:
      labels:
        app: {{ service_name }}
        role: slave
        tier: backend
    spec:
      containers:
      - name: slave
        image: gcr.io/google_samples/gb-redisslave:v3
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  name: {{ service_name }}
  namespace: {{ name_space }}
  labels:
    app: {{ service_name }}
    role: slave
    tier: backend
spec:
  ports:
  - port: 6379
  selector:
    app: {{ service_name }}
    role: slave
    tier: backend
