apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
  namespace: guard-kube
  annotations:
    guard.io/security-components: "[\"firewall\"]"
spec:
  selector:
    matchLabels:
      app: apache
  replicas: 1
  template:
    metadata:
      labels:
        app: apache
    spec:
      hostAliases:
        - ip: "127.0.0.1"
          hostnames:
          - "apache"
      containers:
        - name: apache
          image: httpd
          ports:
            - name: apache
              containerPort: 80
          volumeMounts:
            - name: apache-conf
              mountPath: /usr/local/apache2/conf/httpd.conf
              subPath: httpd.conf
            - name: apache-log
              mountPath: /usr/local/apache2/logs
            - name: cgroup
              mountPath: /sys/fs/cgroup
            - name: proc
              mountPath: /proc

        - name: filebeat
          image: docker.elastic.co/beats/filebeat:6.8.1
          securityContext:
            runAsUser: 0
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: filebeat
              mountPath: /usr/share/filebeat/filebeat.yml
              subPath: filebeat.yml
            - name: filebeat-config
              mountPath: /usr/share/filebeat/config/
            - name: apache-log
              mountPath: /var/log/apache2/

        - name: metricbeat
          image: docker.elastic.co/beats/metricbeat:6.8.1
          securityContext:
            runAsUser: 0
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: metricbeat
              mountPath: /usr/share/metricbeat/metricbeat.yml
              subPath: metricbeat.yml
            - name: metricbeat-modules
              mountPath: /usr/share/metricbeat/modules.d/
            - name: cgroup
              mountPath: /sys/fs/cgroup
            - name: proc
              mountPath: /proc

        - name: heartbeat
          image: docker.elastic.co/beats/heartbeat:6.8.1
          securityContext:
            runAsUser: 0
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: heartbeat
              mountPath: /usr/share/heartbeat/heartbeat.yml
              subPath: heartbeat.yml
            - name: heartbeat-monitors
              mountPath: /usr/share/heartbeat/monitors.d/

        - name: logstash
          image: docker.elastic.co/logstash/logstash:6.8.1
          securityContext:
            runAsUser: 0
          ports:
            - name: filebeat
              containerPort: 5044
            - name: metricbeat
              containerPort: 5144
          volumeMounts:
            - name: logstash-config
              mountPath: /usr/share/logstash/config/
            - name: logstash-pipeline
              mountPath: /usr/share/logstash/pipeline/

      initContainers:
        - name: copy
          image: busybox
          command:
           - "sh"
           - "-c"
          args:
            - "cp /filebeat-config-data/* /filebeat-config/ ;
               cp /metricbeat-modules-data/* /metricbeat-modules/ ;
               cp /heartbeat-monitors-data/* /heartbeat-monitors/"
          volumeMounts:
            - name: filebeat-config
              mountPath: /filebeat-config
            - name: filebeat-config-data
              mountPath: /filebeat-config-data
            - name: metricbeat-modules
              mountPath: /metricbeat-modules
            - name: metricbeat-modules-data
              mountPath: /metricbeat-modules-data
            - name: heartbeat-monitors
              mountPath: /heartbeat-monitors
            - name: heartbeat-monitors-data
              mountPath: /heartbeat-monitors-data

      volumes:
        - name: apache-conf
          configMap:
            name: apache-conf

        - name: apache-log
          hostPath:
            path: /var/log/apache2

        - name: filebeat
          configMap:
            name: apache-filebeat

        - name: filebeat-config
          emptyDir: {}

        - name: filebeat-config-data
          configMap:
            name: apache-filebeat-config

        - name: metricbeat
          configMap:
            name: apache-metricbeat

        - name: metricbeat-modules
          emptyDir: {}

        - name: metricbeat-modules-data
          configMap:
            name: apache-metricbeat-modules

        - name: heartbeat
          configMap:
            name: apache-heartbeat

        - name: heartbeat-monitors
          emptyDir: {}

        - name: heartbeat-monitors-data
          configMap:
            name: apache-heartbeat-monitors

        - name: logstash-config
          configMap:
            name: apache-logstash-config

        - name: logstash-pipeline
          configMap:
            name: apache-logstash-pipeline

        - name: cgroup
          hostPath:
            path: /sys/fs/cgroup

        - name: proc
          hostPath:
            path: /proc

