# Just based on the official example: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cbes-deployment
  labels:
    app: cbes
spec:
  # YOU MUST CHANGE THE LABEL BELOW AS WELL
  replicas: 3
  # This is naughty but prevents voluntary eviction:
  # maxUnavailable: 0
  strategy:
    # Ensure all existing pods terminate before new ones start on a roll out
    type: Recreate
  selector:
    matchLabels:
      app: cbes
  template:
    metadata:
      labels:
        app: cbes
        # Make sure to always change this when replica count changes, unfortunately we cannot use a YAML
        # anchor as replica takes an integer and we want a string here.
        totalReplicas: "3"
    spec:
      containers:
      - name: cbes
        image: cbes-launcher:v1
        env:
          # Set this from the label above to keep it consistent
          - name: TOTAL_REPLICAS
            valueFrom:
              fieldRef:
                fieldPath: metadata.labels['totalReplicas']
          - name: LAUNCH_ME
            value: "/usr/local/bin/test.sh"
          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: MY_POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace