---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: beatload-dp
  labels:
    component: beatload
spec:
  replicas: 1
  selector:
    matchLabels:
      component: beatload
  template:
    metadata:
      labels:
        component: beatload
    spec:
      volumes:
        - name: beatload-config
          configMap:
            name: beatload-config
        - name: beatload-cert
          secret:
            secretName: beatload-cert
      initContainers:
        - name: conn-check
          image: curlimages/curl
          command: ['sh']
          args:
            - "/conn-check.sh"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-config
              mountPath: /conn-check.sh
              subPath: conn-check.sh
        - name: ilm-setup
          image: curlimages/curl
          command: ['sh']
          args:
            - "/ilm-setup.sh"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-config
              mountPath: /ilm-setup.sh
              subPath: ilm-setup.sh
        - name: filebeat-load
          image: docker.elastic.co/beats/filebeat:7.16.2-amd64
          command: ['/usr/share/filebeat/filebeat']
          args:
            - "setup"
            - "--index-management"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/filebeat/certs
            - name: beatload-config
              mountPath: /usr/share/filebeat/filebeat.yml
              subPath: filebeat.yml
            - name: beatload-config
              mountPath: /usr/share/filebeat/ilm-policy.json
              subPath: ilm-policy.json
        - name: filebeat-load-dashboard
          image: docker.elastic.co/beats/filebeat:7.16.2-amd64
          command: ['/usr/share/filebeat/filebeat']
          args:
            - "setup"
            - "--dashboards"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/filebeat/certs
            - name: beatload-config
              mountPath: /usr/share/filebeat/filebeat.yml
              subPath: filebeat.yml
            - name: beatload-config
              mountPath: /usr/share/filebeat/ilm-policy.json
              subPath: ilm-policy.json
        - name: metricbeat-load
          image: docker.elastic.co/beats/metricbeat:7.16.2-amd64
          command: ['/usr/share/metricbeat/metricbeat']
          args:
            - "setup"
            - "--index-management"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/metricbeat/certs
            - name: beatload-config
              mountPath: /usr/share/metricbeat/metricbeat.yml
              subPath: metricbeat.yml
            - name: beatload-config
              mountPath: /usr/share/metricbeat/ilm-policy.json
              subPath: ilm-policy.json
        - name: metricbeat-load-dashboard
          image: docker.elastic.co/beats/metricbeat:7.16.2-amd64
          command: ['/usr/share/metricbeat/metricbeat']
          args:
            - "setup"
            - "--dashboards"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/metricbeat/certs
            - name: beatload-config
              mountPath: /usr/share/metricbeat/metricbeat.yml
              subPath: metricbeat.yml
            - name: beatload-config
              mountPath: /usr/share/metricbeat/ilm-policy.json
              subPath: ilm-policy.json
        - name: auditbeat-load
          image: docker.elastic.co/beats/auditbeat:7.16.2-amd64
          command: ['/usr/share/auditbeat/auditbeat']
          args:
            - "setup"
            - "--index-management"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/auditbeat/certs
            - name: beatload-config
              mountPath: /usr/share/auditbeat/auditbeat.yml
              subPath: auditbeat.yml
            - name: beatload-config
              mountPath: /usr/share/auditbeat/ilm-policy.json
              subPath: ilm-policy.json
        - name: auditbeat-load-dashboard
          image: docker.elastic.co/beats/auditbeat:7.16.2-amd64
          command: ['/usr/share/auditbeat/auditbeat']
          args:
            - "setup"
            - "--dashboards"
            - "-e"
          env:
            - name: ELASTIC_HOST
              value: "elastic-svc"
            - name: ELASTIC_PORT
              value: "9200"
            - name: KIBANA_HOST
              value: "kibana-svc"
            - name: KIBANA_PORT
              value: "5601"
            - name: ELASTIC_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: ELASTIC_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
            - name: KIBANA_USERNAME
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: username
            - name: KIBANA_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: beatload-cred
                  key: password
          volumeMounts:
            - name: beatload-cert
              mountPath: /usr/share/auditbeat/certs
            - name: beatload-config
              mountPath: /usr/share/auditbeat/auditbeat.yml
              subPath: auditbeat.yml
            - name: beatload-config
              mountPath: /usr/share/auditbeat/ilm-policy.json
              subPath: ilm-policy.json
      containers:
        - name: pause
          image: gcr.io/google_containers/pause
