# datadog-agent.yaml
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: datadog-agent
  namespace: default
spec:
  selector:
    matchLabels:
      app: datadog-agent
  template:
    metadata:
      labels:
        app: datadog-agent
      name: datadog-agent
    spec:
      serviceAccountName: datadog-agent
      containers:
        - image: 'datadog/agent:latest'
          imagePullPolicy: Always
          name: datadog-agent
          env:
            ## The Datadog API Key related to your Organization set by secret
            - name: DD_API_KEY
              valueFrom:
                secretKeyRef:
                  name: datadog-secret
                  key: api-key

            ## Set DD_SITE to 'datadoghq.eu' to send your Agent data to the Datadog EU site
            - name: DD_SITE
              value: 'datadoghq.com'

            #######################
            ## Metric collection ##
            #######################
            - name: KUBERNETES
              value: 'true'
            - name: DD_HEALTH_PORT
              value: '5555'
            - name: DD_COLLECT_KUBERNETES_EVENTS
              value: 'true'
            - name: DD_LEADER_ELECTION
              value: 'true'
            - name: DD_KUBERNETES_KUBELET_HOST
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP

            ####################
            ## Log collection ##
            ####################
            - name: DD_LOGS_ENABLED
              value: 'true'
            - name: DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL
              value: 'true'
            - name: DD_AC_EXCLUDE
              value: 'name:datadog-agent'
            - name: DD_LOGS_CONFIG_K8S_CONTAINER_USE_FILE
              value: 'true'

          ## For secure communication with the Cluster Agent (required to use the Cluster Agent)
          # - name: DD_CLUSTER_AGENT_AUTH_TOKEN
          #
          ## If using a simple env var uncomment this section
          #
          #   value: <THIRTY_2_CHARACTERS_LONG_TOKEN>
          #
          ## If using a secret uncomment this section
          #
          #   valueFrom:
          #     secretKeyRef:
          #       name: datadog-auth-token
          #       key: token

          ## Note these are the minimum suggested values for requests and limits.
          ## The amount of resources required by the Agent varies depending on:
          ## * The number of checks
          ## * The number of integrations enabled
          ## * The number of features enabled
          resources:
            requests:
              memory: 256Mi
              cpu: 200m
            limits:
              memory: 256Mi
              cpu: 200m


          volumeMounts:

            #######################
            ## Metric collection ##
            #######################
            - name: dockersocketdir
              mountPath: /var/run
            - name: procdir
              mountPath: /host/proc
              readOnly: true
            - name: cgroups
              mountPath: /host/sys/fs/cgroup
              readOnly: true

            ####################
            ## Log collection ##
            ####################
            - name: pointdir
              mountPath: /var/lib/datadog-agent/logs
            - name: logpodpath
              mountPath: /var/log/pods

              # Docker runtime directory, replace this path with your container runtime logs directory,
              # or remove this configuration if `/var/log/pods` is not a symlink to any other directory.
            - name: logcontainerpath
              mountPath: /var/lib/docker/containers

          livenessProbe:
            httpGet:
              path: /health
              port: 5555
            initialDelaySeconds: 15
            periodSeconds: 15
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3

      volumes:
        - hostPath:
            path: /var/run
          name: dockersocketdir
        - hostPath:
            path: /proc
          name: procdir
        - hostPath:
            path: /sys/fs/cgroup
          name: cgroups
        #####################
        ## Log collection  ##
        #####################
        - hostPath:
            path: /opt/datadog-agent/run:rw
          name: pointdir
        - hostPath:
            path: /var/log/pods
          name: logpodpath
        # Docker runtime directory, replace this path with your container runtime logs directory,
        # or remove this configuration if `/var/log/pods` is not a symlink to any other directory.
        - hostPath:
            path: /var/lib/docker/containers
          name: logcontainerpath

