> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying and Viewing Application Logs

> Explains using a DaemonSet Fluent Bit agent to automatically collect and enrich Kubernetes pod logs cluster-wide without per-application configuration.

Picture a new tenant moving into our apartment complex.

They unpack on a Monday, and that same morning their mail is already being collected. Nobody had to hire a new courier or redraw the delivery route — the logging agent is already in place and ready to pick up logs.

![An illustrated three-story apartment building labeled "A new tenant moves in," showing cartoon tenant icons on the left and network-like cables running between units. One top-floor unit is highlighted in blue with moving boxes inside.](https://mintcdn.com/kodekloud-c4ac6d9a/dEcIUoAxuol-3ZBK/images/Grafana-Loki/Grafana-Loki-on-Kubernetes/Deploying-and-Viewing-Application-Logs/new-tenant-apartment-network-moving-boxes.jpg?fit=max\&auto=format\&n=dEcIUoAxuol-3ZBK\&q=85\&s=e0f939a8650bb042c167246c19bc1892)

We deploy Alloy as a DaemonSet, so every node in the cluster runs the same Fluent Bit–based agent. That agent watches the node's containers and automatically begins collecting logs for any pod that starts on that node. This setup is application-agnostic: the agent does not need per-application configuration to discover and collect logs.

Fluent Bit commonly operates by tailing the container log files on each node and using the Kubernetes API to enrich records with pod metadata (labels, namespace, pod name, etc.). As soon as a container writes logs, the agent picks them up — just like the tenant receiving mail on day one.

Example: a minimal Deployment for an application that requires no special logging config

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  labels:
    app: api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: kodekloud/loki-demo
```

How it works (high level)

1. The DaemonSet runs Fluent Bit on every node.
2. Fluent Bit tails container log files on the node (typically under `/var/log/containers/`).
3. Fluent Bit queries the Kubernetes API to enrich logs with pod metadata (labels, namespace, etc.).
4. Enriched log records are forwarded to your log backend (e.g., Grafana Loki, Elasticsearch).

Permissions and requirements

| Resource / Requirement | Purpose | Notes / Example |
| - | - | - |
| DaemonSet on each node | Ensures an agent runs on every node | Deploy Fluent Bit as a DaemonSet |
| Node file access | Read container log files | Agent needs access to node log directories (hostPath mounts) |
| Kubernetes API access | Enrich logs with pod metadata | Requires RBAC permissions to read pod objects |
| `pods/log` (optional) | If agent reads logs via the API instead of tailing files | Grant `pods/log` only when using API-based log retrieval |

No per-application logging configuration is required. As long as the DaemonSet agent runs and has permission to access node container log files and to read pod metadata from the Kubernetes API (RBAC for pod metadata), it will automatically collect logs from newly created pods. `pods/log` permission is only required if the agent is configured to fetch logs via the API rather than tailing node files.

Links and references

* [DaemonSet — Kubernetes Concepts](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/)
* [Fluent Bit — Official site](https://fluentbit.io/)
* [Kubernetes API reference](https://kubernetes.io/docs/reference/using-api/)
* [RBAC — Kubernetes](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)
* [Read logs (`pods/log`) — Kubernetes API](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#read-log-v1-core)

> **[Watch Video](https://learn.kodekloud.com/user/courses/grafana-loki/module/595f27e5-031e-46ea-bffc-ee1a15f73837/lesson/72cba12a-2817-4cd8-8a83-6547b57a0f2a)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.