apiVersion: apps/v1 kind: DaemonSet metadata: name: promtail namespace: monitoring spec: selector: matchLabels: name: promtail template: metadata: labels: name: promtail annotations: prometheus.io/port: "9080" spec: serviceAccount: promtail tolerations: - key: "rtlsdr" value: "true" effect: "NoSchedule" containers: - name: promtail image: grafana/promtail args: - -config.file=/etc/promtail/promtail.yaml env: - name: 'HOSTNAME' # needed when using kubernetes_sd_configs valueFrom: fieldRef: fieldPath: 'spec.nodeName' resources: requests: cpu: 20m memory: 65Mi volumeMounts: - name: logs mountPath: /var/log - name: promtail-config mountPath: /etc/promtail - mountPath: /var/log/pods name: varlogpods readOnly: true volumes: - name: logs hostPath: path: /var/log - name: varlogpods hostPath: path: /var/log/pods - name: promtail-config configMap: name: promtail-config --- # configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: promtail-config namespace: monitoring data: promtail.yaml: | server: http_listen_port: 9080 grpc_listen_port: 0 clients: - url: http://monitoring-0:3100/loki/api/v1/push positions: filename: /tmp/positions.yaml target_config: sync_period: 10s scrape_configs: - job_name: pod-logs kubernetes_sd_configs: - role: pod pipeline_stages: - docker: {} relabel_configs: - source_labels: - __meta_kubernetes_pod_node_name target_label: __host__ - action: labelmap regex: __meta_kubernetes_pod_label_(.+) - action: replace replacement: $1 separator: / source_labels: - __meta_kubernetes_namespace - __meta_kubernetes_pod_name target_label: job - action: replace source_labels: - __meta_kubernetes_namespace target_label: namespace - action: replace source_labels: - __meta_kubernetes_pod_name target_label: pod - action: replace source_labels: - __meta_kubernetes_pod_container_name target_label: container - replacement: /var/log/pods/*$1/*.log separator: / source_labels: - __meta_kubernetes_pod_uid - __meta_kubernetes_pod_container_name target_label: __path__ --- # Clusterrole.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: promtail rules: - apiGroups: [""] resources: - nodes - services - pods verbs: - get - watch - list --- # ServiceAccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: promtail namespace: monitoring --- # Rolebinding.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: promtail namespace: monitoring subjects: - kind: ServiceAccount name: promtail namespace: monitoring roleRef: kind: ClusterRole name: promtail apiGroup: rbac.authorization.k8s.io