apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: datadog-agent
spec:
  selector:
    matchLabels:
      app: datadog-agent
  template:
    metadata:
      labels:
        app: datadog-agent
      name: datadog-agent
    spec:
      containers:
      - image: datadog/agent:latest
        imagePullPolicy: Always
        name: datadog-agent
        ports:
          - containerPort: 8125
            name: dogstatsdport
            protocol: UDP
          - containerPort: 8126
            hostPort: 8126
            name: traceport
            protocol: TCP
        env:
          - name: DD_API_KEY
            valueFrom:
              secretKeyRef:
                name: datadog-api
                key: token
          - name: KUBERNETES
            value: "true"
          - name: DD_COLLECT_KUBERNETES_EVENTS
            value: "true"
          - name: DD_KUBERNETES_KUBELET_HOST
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          # Logs
          - name: DD_LOGS_ENABLED
            value: "true"
          - name: DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL
            value: "true"
          - name: DD_PROCESS_AGENT_ENABLED
            value: "true"
          # APM
          - name: DD_APM_ENABLED
            value: "true"
          # For Trace Search
          - name: DD_APM_ANALYZED_SPANS
            value: "my-flask-app|flask.request=1,postgres_service|postgres.query=1"
        resources:
          requests:
            memory: "256Mi"
            cpu: "200m"
          limits:
            memory: "256Mi"
            cpu: "200m"
        volumeMounts:
          - name: dockersocket
            mountPath: /var/run/docker.sock
          - name: procdir
            mountPath: /host/proc
            readOnly: true
          - name: cgroups
            mountPath: /host/sys/fs/cgroup
            readOnly: true
          - name: flasklogs
            mountPath: /var/log/flask
            readOnly: true
          - name: vol-datadog-confd
            mountPath: /conf.d
          - name: passwd
            mountPath: /etc/passwd
            readOnly: true
        livenessProbe:
          exec:
            command:
            - ./probe.sh
          initialDelaySeconds: 15
          periodSeconds: 5
      volumes:
        - hostPath:
            path: /var/run/docker.sock
          name: dockersocket
        - hostPath:
            path: /proc
          name: procdir
        - hostPath:
            path: /sys/fs/cgroup
          name: cgroups
        - hostPath:
            path: /var/log/flask
          name: flasklogs
        - name: vol-datadog-confd
          configMap:
            name: cm-datadog-confd
        - hostPath:
            path: /etc/passwd
          name: passwd
