github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/docs/sources/clients/promtail/installation.md (about)

     1  ---
     2  title: Installation
     3  ---
     4  # Install Promtail
     5  
     6  Promtail is distributed as a binary, in a Docker container,
     7  or there is a Helm chart to install it in a Kubernetes cluster.
     8  
     9  ## Binary
    10  
    11  Every release includes binaries for Promtail which can be found on the
    12  [Releases page](https://github.com/grafana/loki/releases).
    13  
    14  ## Docker
    15  
    16  ```bash
    17  # modify tag to most recent version
    18  docker pull grafana/promtail:2.0.0
    19  ```
    20  
    21  ## Helm
    22  
    23  Make sure that Helm is installed.
    24  See [Installing Helm](https://helm.sh/docs/intro/install/).
    25  Then you can add Grafana's chart repository to Helm:
    26  
    27  ```bash
    28  helm repo add grafana https://grafana.github.io/helm-charts
    29  ```
    30  
    31  And the chart repository can be updated by running:
    32  
    33  ```bash
    34  helm repo update
    35  ```
    36  
    37  Finally, Promtail can be deployed with:
    38  
    39  ```bash
    40  $ helm upgrade --install promtail grafana/promtail --set "loki.serviceName=loki"
    41  ```
    42  
    43  ## Kubernetes
    44  
    45  ### DaemonSet (recommended)
    46  
    47  A `DaemonSet` will deploy Promtail on every node within a Kubernetes cluster.
    48  
    49  The DaemonSet deployment works well at collecting the logs of all containers within a
    50  cluster. It's the best solution for a single-tenant model.
    51  
    52  ```yaml
    53  ---Daemonset.yaml
    54  apiVersion: apps/v1
    55  kind: DaemonSet
    56  metadata:
    57    name: promtail-daemonset
    58  spec:
    59    selector:
    60      matchLabels:
    61        name: promtail
    62    template:
    63      metadata:
    64        labels:
    65          name: promtail
    66      spec:
    67        serviceAccount: SERVICE_ACCOUNT
    68        serviceAccountName: SERVICE_ACCOUNT
    69        volumes:
    70        - name: logs
    71          hostPath:
    72            path: HOST_PATH
    73        - name: promtail-config
    74          configMap:
    75            name: promtail-config
    76        containers:
    77        - name: promtail-container
    78          image: grafana/promtail
    79          args:
    80          - -config.file=/etc/promtail/promtail.yaml
    81          env: 
    82          - name: 'HOSTNAME' # needed when using kubernetes_sd_configs
    83            valueFrom:
    84              fieldRef:
    85                fieldPath: 'spec.nodeName'
    86          volumeMounts:
    87          - name: logs
    88            mountPath: MOUNT_PATH
    89          - name: promtail-config
    90            mountPath: /etc/promtail
    91  
    92  ---configmap.yaml
    93  apiVersion: v1
    94  kind: ConfigMap
    95  metadata:
    96    name: promtail-config
    97  data:
    98    promtail.yaml: YOUR CONFIG
    99  
   100  ---Clusterrole.yaml
   101  apiVersion: rbac.authorization.k8s.io/v1
   102  kind: ClusterRole
   103  metadata:
   104    name: promtail-clusterrole
   105  rules:
   106    - apiGroups: [""]
   107      resources:
   108      - nodes
   109      - services
   110      - pods
   111      verbs:
   112      - get
   113      - watch
   114      - list
   115  
   116  ---ServiceAccount.yaml
   117  apiVersion: v1
   118  kind: ServiceAccount
   119  metadata:
   120    name: promtail-serviceaccount
   121  
   122  ---Rolebinding.yaml
   123  apiVersion: rbac.authorization.k8s.io/v1
   124  kind: ClusterRoleBinding
   125  metadata:
   126    name: promtail-clusterrolebinding
   127  subjects:
   128      - kind: ServiceAccount
   129        name: promtail-serviceaccount
   130        namespace: default
   131  roleRef:
   132      kind: ClusterRole
   133      name: promtail-clusterrole
   134      apiGroup: rbac.authorization.k8s.io
   135  ```
   136  
   137  ### Sidecar
   138  
   139  The Sidecar method deploys Promtail as a sidecar container for a specific pod.
   140  In a multi-tenant environment, this enables teams to aggregate logs for specific
   141  pods and deployments.
   142  
   143  ```yaml
   144  ---Deployment.yaml
   145  apiVersion: apps/v1
   146  kind: Deployment
   147  metadata:
   148    name: promtail-deployment
   149  spec:
   150    selector:
   151      matchLabels:
   152        name: promtail
   153    template:
   154      metadata:
   155        labels:
   156          name: promtail
   157      spec:
   158        serviceAccount: SERVICE_ACCOUNT
   159        serviceAccountName: SERVICE_ACCOUNT
   160        volumes:
   161        - name: logs
   162          hostPath:
   163            path: HOST_PATH
   164        - name: promtail-config
   165          configMap:
   166            name: promtail-config
   167        containers:
   168        - name: promtail-container
   169          image: grafana/promtail
   170          args:
   171          - -config.file=/etc/promtail/promtail.yaml
   172          volumeMounts:
   173          - name: logs
   174            mountPath: MOUNT_PATH
   175          - name: promtail-config
   176            mountPath: /etc/promtail
   177  ```