---
apiVersion: v1
kind: ConfigMap
metadata:
  name: promtail
  labels:
    app: promtail
data:
  promtail.yaml: |
    scrape_configs:
      - job_name: kubernetes-pods
        entry_parser: raw
        kubernetes_sd_configs:
        - role: pod
        relabel_configs:
        - source_labels:
          - __meta_kubernetes_pod_node_name
          target_label: __host__
        - action: drop
          regex: ^$
          source_labels:
          - __meta_kubernetes_pod_label_name
        - action: replace
          replacement: $1
          separator: /
          source_labels:
          - __meta_kubernetes_namespace
          - __meta_kubernetes_pod_label_name
          target_label: job
        - action: replace
          source_labels:
          - __meta_kubernetes_namespace
          target_label: namespace
        - action: replace
          source_labels:
          - __meta_kubernetes_pod_name
          target_label: instance
        - action: replace
          source_labels:
          - __meta_kubernetes_pod_container_name
          target_label: container_name
        - action: labelmap
          regex: __meta_kubernetes_pod_label_(.+)
        - replacement: /var/log/pods/$1/*.log
          separator: /
          source_labels:
          - __meta_kubernetes_pod_uid
          - __meta_kubernetes_pod_container_name
          target_label: __path__
      - job_name: kubernetes-pods-app
        entry_parser: raw
        kubernetes_sd_configs:
        - role: pod
        relabel_configs:
        - source_labels:
          - __meta_kubernetes_pod_node_name
          target_label: __host__
        - action: drop
          regex: ^$
          source_labels:
          - __meta_kubernetes_pod_label_app
        - action: drop
          regex: .+
          source_labels:
          - __meta_kubernetes_pod_label_name
        - action: replace
          replacement: $1
          separator: /
          source_labels:
          - __meta_kubernetes_namespace
          - __meta_kubernetes_pod_label_app
          target_label: job
        - action: replace
          source_labels:
          - __meta_kubernetes_namespace
          target_label: namespace
        - action: replace
          source_labels:
          - __meta_kubernetes_pod_name
          target_label: instance
        - action: replace
          source_labels:
          - __meta_kubernetes_pod_container_name
          target_label: container_name
        - action: labelmap
          regex: __meta_kubernetes_pod_label_(.+)
        - replacement: /var/log/pods/$1/*.log
          separator: /
          source_labels:
          - __meta_kubernetes_pod_uid
          - __meta_kubernetes_pod_container_name
          target_label: __path__
