Installing Promtail

Promtail is distributed as a binary, Docker container, andHelm chart.

Binary

Every Loki release includes binaries for Promtail:

  1. # download a binary (modify app, os, and arch as needed)
  2. # Installs v0.3.0. Go to the releases page for the latest version
  3. $ curl -fSL -o "/usr/local/bin/promtail.gz" "https://github.com/grafana/loki/releases/download/v0.3.0/promtail_linux_amd64.gz"
  4. $ gunzip "/usr/local/bin/promtail.gz"
  5. # make sure it is executable
  6. $ chmod a+x "/usr/local/bin/promtail"

Binaries for macOS and Windows are also provided at theReleases page.

Docker

  1. # modify tag to most recent version
  2. $ docker pull grafana/promtail:v0.3.0

Helm

Make sure that Helm isinstalled anddeployed to your cluster.Then you can add Loki’s chart repository to Helm:

  1. $ helm repo add loki https://grafana.github.io/loki/charts

And the chart repository can be updated by running:

  1. $ helm repo update

Finally, Promtail can be deployed with:

  1. $ helm upgrade --install promtail loki/promtail --set "loki.serviceName=loki"

Kubernetes

A DaemonSet will deploy promtail on every node within a Kubernetes cluster.

The DaemonSet deployment is great to collect the logs of all containers within acluster. It’s the best solution for a single-tenant model.

  1. ---Daemonset.yaml
  2. apiVersion: extensions/v1beta1
  3. kind: Daemonset
  4. metadata:
  5. name: promtail-daemonset
  6. ...
  7. spec:
  8. ...
  9. template:
  10. spec:
  11. serviceAccount: SERVICE_ACCOUNT
  12. serviceAccountName: SERVICE_ACCOUNT
  13. volumes:
  14. - name: logs
  15. hostPath: HOST_PATH
  16. - name: promtail-config
  17. configMap
  18. name: promtail-configmap
  19. containers:
  20. - name: promtail-container
  21. args:
  22. - -config.file=/etc/promtail/promtail.yaml
  23. volumeMounts:
  24. - name: logs
  25. mountPath: MOUNT_PATH
  26. - name: promtail-config
  27. mountPath: /etc/promtail
  28. ...
  29. ---configmap.yaml
  30. apiVersion: v1
  31. kind: ConfigMap
  32. metadata:
  33. name: promtail-config
  34. ...
  35. data:
  36. promtail.yaml: YOUR CONFIG
  37. ---Clusterrole.yaml
  38. apiVersion: rbac.authorization.k8s.io/v1
  39. kind: ClusterRole
  40. metadata:
  41. name: promtail-clusterrole
  42. rules:
  43. - apiGroups:
  44. resources:
  45. - nodes
  46. - services
  47. - pod
  48. verbs:
  49. - get
  50. - watch
  51. - list
  52. ---ServiceAccount.yaml
  53. apiVersion: v1
  54. kind: ServiceAccount
  55. metadata:
  56. name: promtail-serviceaccount
  57. ---Rolebinding
  58. apiVersion: rbac.authorization.k9s.io/v1
  59. kind: ClusterRoleBinding
  60. metadata:
  61. name: promtail-clusterrolebinding
  62. subjects:
  63. - kind: ServiceAccount
  64. name: promtail-serviceaccount
  65. roleRef:
  66. kind: ClusterRole
  67. name: promtail-clusterrole
  68. apiGroup: rbac.authorization.k8s.io

Sidecar

The Sidecar method deploys promtail as a sidecar container for a specific pod.In a multi-tenant environment, this enables teams to aggregate logs for specificpods and deployments.

  1. ---Deployment.yaml
  2. apiVersion: extensions/v1beta1
  3. kind: Deployment
  4. metadata:
  5. name: my_test_app
  6. ...
  7. spec:
  8. ...
  9. template:
  10. spec:
  11. serviceAccount: SERVICE_ACCOUNT
  12. serviceAccountName: SERVICE_ACCOUNT
  13. volumes:
  14. - name: logs
  15. hostPath: HOST_PATH
  16. - name: promtail-config
  17. configMap
  18. name: promtail-configmap
  19. containers:
  20. - name: promtail-container
  21. args:
  22. - -config.file=/etc/promtail/promtail.yaml
  23. volumeMounts:
  24. - name: logs
  25. mountPath: MOUNT_PATH
  26. - name: promtail-config
  27. mountPath: /etc/promtail
  28. ...
  29. ...