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: lcp
          image: guardproject/lcp:latest
          env:
            - name: GIT_URL
              value: "https://guard-token:2nsubUuUss8sQ-Mue_yN@gitlab.com/guard-repositories/lcp"
            - name: ROOT_DIR
              value: "/opt/lcp"
            - name: CONFIG_DIR
              value: "/opt/lcp-config"
            - name: HOST
              value: "0.0.0.0"
            - name: PORT
              value: "4000"
            - name: DEV_USERNAME
              value: "lcp"
            - name: DEV_PASSWORD
              value: "a9d4034da07d8ef31db1cd4119b6a4552fdfbd19787e2848e71c8ee3b47703a7" # "guard" in hashed sha256
            - name: LOG_LEVEL
              value: "DEBUG"
            - name: FORCE_APT_UPGRADE_BOOT
              value: "no"
            - name: FORCE_REBUILD_BOOT
              value: "no"
            - name: USE_ENV_CONFIG_FILES
              value: "yes"
          ports:
            - name: lcp
              containerPort: 4000
          volumeMounts:
            - name: filebeat-config
              mountPath: /opt/filebeat/config/
            - name: metricbeat-modules
              mountPath: /opt/metricbeat/modules.d/

        - 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:7.0.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:7.0.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:7.0.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:7.0.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
