diff --git a/kube/promtail/promtail-clusterrole.yaml b/kube/promtail/promtail-clusterrole.yaml new file mode 100644 index 0000000000..759307cc74 --- /dev/null +++ b/kube/promtail/promtail-clusterrole.yaml @@ -0,0 +1,15 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: promtail-clusterrole + namespace: monitoring +rules: + - apiGroups: [""] + resources: + - nodes + - services + - pods + verbs: + - get + - watch + - list \ No newline at end of file diff --git a/kube/promtail/promtail-clusterrolebinding.yaml b/kube/promtail/promtail-clusterrolebinding.yaml new file mode 100644 index 0000000000..677a04593f --- /dev/null +++ b/kube/promtail/promtail-clusterrolebinding.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: promtail-clusterrolebinding + namespace: monitoring +subjects: + - kind: ServiceAccount + name: promtail-sa + namespace: monitoring +roleRef: + kind: ClusterRole + name: promtail-clusterrole + apiGroup: rbac.authorization.k8s.io \ No newline at end of file diff --git a/kube/promtail/promtail-config.yaml b/kube/promtail/promtail-config.yaml new file mode 100644 index 0000000000..1c970e0615 --- /dev/null +++ b/kube/promtail/promtail-config.yaml @@ -0,0 +1,54 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: promtail-config + namespace: monitoring +data: + promtail.yaml: | + server: + http_listen_port: 9080 + grpc_listen_port: 0 + log_level: debug + positions: + filename: /tmp/positions.yaml + clients: + - url: http://${Loki_IP}:3100/loki/api/v1/push + target_config: + sync_period: 10s + scrape_configs: + - job_name: kubernetes-pods + 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__ \ No newline at end of file diff --git a/kube/promtail/promtail-daemonset.yaml b/kube/promtail/promtail-daemonset.yaml new file mode 100644 index 0000000000..6a243a4357 --- /dev/null +++ b/kube/promtail/promtail-daemonset.yaml @@ -0,0 +1,54 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: promtail + namespace: monitoring +spec: + selector: + matchLabels: + app: promtail + template: + metadata: + labels: + app: promtail + spec: + serviceAccountName: promtail-sa + containers: + - name: promtail + image: grafana/promtail:latest + volumeMounts: + - name: config-volume + mountPath: /etc/promtail + - name: loki-ip-volume + mountPath: /etc/loki-ip + - name: varlog + mountPath: /var/log + - name: varlibdockercontainers + mountPath: /var/lib/docker/containers + readOnly: true + args: + - -config.file=/etc/promtail/promtail.yaml + - -config.expand-env=true + env: + - name: Loki_IP + valueFrom: + secretKeyRef: + name: loki-ip-secret + key: loki-ip + - name: 'HOSTNAME' # needed when using kubernetes_sd_configs + valueFrom: + fieldRef: + fieldPath: 'spec.nodeName' + volumes: + - name: config-volume + configMap: + name: promtail-config + - name: loki-ip-volume + secret: + secretName: loki-ip-secret + - name: varlog + hostPath: + path: /var/log + - name: varlibdockercontainers + hostPath: + path: /var/lib/docker/containers diff --git a/kube/promtail/service-account.yaml b/kube/promtail/service-account.yaml new file mode 100644 index 0000000000..28739232f6 --- /dev/null +++ b/kube/promtail/service-account.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: promtail-sa + namespace: monitoring \ No newline at end of file