Project: Grafana Loki (Observability and Analysis / Observability)
File: installation.md

title: Install Promtail menuTitle: Install Promtail description: Installation instructions for the Promtail client. aliases: ../../clients/promtail/installation/ weight: 100 Promtail is distributed as a binary, in a Docker container, or there is a Helm chart to install it in a Kubernetes cluster. Every Grafana Loki release includes binaries for Promtail which can be found on the as part of the release assets. See the instructions . Make sure to modify the tag to the most recent version. ```bash docker pull grafana/promtail:3.0.0 ``` Create your Promtail configuration file in a file called `promtail-config.yaml`. Refer to the for more details. Note that you will need to replace `<local-path>` in the commands with your local path. ```bash docker run -v <local-path>:/mnt/config -v /var/log:/var/log --link loki grafana/promtail:3.0.0 --config.file=/mnt/config/promtail-config.yaml ``` Make sure that Helm is installed. See . Then you can add Grafana's chart repository to Helm: ```bash helm repo add grafana https://grafana.github.io/helm-charts ``` Update the chart repository: ```bash helm repo update ``` Create the configuration file `values.yaml`. The example below illustrates a connection to the locally deployed loki server: ```yaml config: clients: url: http://loki-gateway/loki/api/v1/push tenant_id: 1 ``` Finally, Promtail can be deployed with: ```bash helm upgrade --values values.yaml --install promtail grafana/promtail ``` A `DaemonSet` will deploy Promtail on every node within a Kubernetes cluster. The DaemonSet deployment works well at collecting the logs of all containers within a cluster. It's the best solution for a single-tenant model. Replace `{YOURLOKIENDPOINT}` with your Loki endpoint. ```yaml # Daemonset.yaml apiVersion: apps/v1 kind: DaemonSet metadata: name: promtail-daemonset spec: selector: matchLabels: name: promtail template: metadata: labels: name: promtail spec: serviceAccount: promtail-serviceaccount containers: name: promtail-container image: grafana/promtail args: -config.file=/etc/promtail/promtail.yaml env: name: 'HOSTNAME' # needed when using kubernetessdconfigs valueFrom: fieldRef: fieldPath: 'spec.nodeName' volumeMounts: name: logs mountPath: /var/log name: promtail-config mountPath: /etc/promtail mountPath: /var/lib/docker/containers name: varlibdockercontainers readOnly: true volumes: name: logs hostPath: path: /var/log name: varlibdockercontainers hostPath: path: /var/lib/docker/containers name: promtail-config configMap: name: promtail-config # configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: promtail-config data: promtail.yaml: | server: httplistenport: 9080 grpclistenport: 0 clients: url: https://{YOURLOKIENDPOINT}/loki/api/v1/push positions: filename: /tmp/positions.yaml target_config: sync_period: 10s scrape_configs: job_name: pod-logs kubernetessdconfigs: role: pod pipeline_stages: docker: {} relabel_configs: source_labels: metakubernetespodnodename targetlabel: host_ action: labelmap regex: metakubernetespodlabel(.+) action: replace replacement: $1 separator: / source_labels: metakubernetesnamespace metakubernetespod_name target_label: job action: replace source_labels: metakubernetesnamespace target_label: namespace action: replace source_labels: metakubernetespod_name target_label: pod action: replace source_labels: metakubernetespodcontainername target_label: container replacement: /var/log/pods/$1/.log separator: / source_labels: metakubernetespod_uid metakubernetespodcontainername targetlabel: path_ # Clusterrole.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: promtail-clusterrole rules: apiGroups: [""] resources: nodes services pods verbs: get watch list # ServiceAccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: promtail-serviceaccount # Rolebinding.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: promtail-clusterrolebinding subjects: kind: ServiceAccount name: promtail-serviceaccount namespace: default roleRef: kind: ClusterRole name: promtail-clusterrole apiGroup: rbac.authorization.k8s.io ```