Kubernetes logging and monitoring means pulling three streams of data out of your cluster — container logs, resource and app metrics, and cluster events — into systems that survive pod restarts and node failures, then alerting on them. The shortest working path is: centralize logs with a log agent DaemonSet, scrape metrics with Prometheus, visualize in Grafana, and let Kubernetes record events you forward or watch. Nothing in this guide requires paid products, but you do need a reachable cluster and permission to create namespaced resources and DaemonSets.
What You'll Need
- A working cluster (any managed or self-hosted distribution) and
kubectlconfigured against it. - Cluster-admin or equivalent rights to install cluster-scoped resources such as CRDs, ClusterRoles and DaemonSets.
helmon your workstation, since most of these components ship as charts.- Persistent storage if you plan to keep logs and metrics beyond a pod's lifetime (a local path, a cloud volume class, or an object-storage bucket for long-term logs).
- Decisions made up front: retention period, which namespaces matter most, and who receives alerts.
Step-by-Step
- Confirm what Kubernetes already gives you. Before installing anything, check the built-in signals. Run
kubectl logs <pod> -c <container>for a single pod,kubectl get events --sort-by=.lastTimestamp -Afor recent cluster events, andkubectl top pods -Aandkubectl top nodesfor live CPU and memory.kubectl toponly works if a metrics server is installed; on managed clusters it usually is, otherwise your distribution's docs cover enabling it. These are your reference points when the full stack misbehaves. - Decide where logs live. Write container logs to stdout and stderr and let the node's log agent pick them up. Avoid logging to files inside the container filesystem: those files vanish with the pod. If an application insists on writing files, mount an
emptyDirand tail that path from the agent. - Standardize log format. Emit structured JSON with at least a timestamp, level, service name, and a correlation or request ID. Structured logs are filterable; unstructured lines force regex guessing later. Check that your app does not double-timestamp — many loggers add their own time field, and mixed formats break parsing.
- Deploy a log collector as a DaemonSet. Fluent Bit is the lightest common choice and runs one pod per node, reading
/var/log/containers/*.logthrough a hostPath mount with the node's log directory. Install it with Helm into its own namespace and give it a ServiceAccount with permission to read pods and namespaces so it can tag each line with metadata. - Point the collector at a backend. Options include Elasticsearch or OpenSearch, Loki, or a managed log service. If you run Loki, add its chart in the same namespace and configure the collector's output plugin to ship there. Verify end to end by generating a test line:
kubectl run logtest --image=busybox --restart=Never -- sh -c "echo hello-from-logtest"and then query for it in the backend UI. - Install Prometheus for metrics. The kube-prometheus-stack Helm chart bundles Prometheus, Alertmanager, Grafana, node exporters and default Kubernetes dashboards in one release. Install it into a monitoring namespace. Review the chart's values file before installing — the defaults assume a small cluster and set retention and storage that may not suit you.
- Expose application metrics. Have services serve a Prometheus-format
/metricsendpoint and add a ServiceMonitor (a custom resource that ships with the chart) selecting that service. Without a ServiceMonitor or scrape annotation, Prometheus will not find your app even though it is healthy. - Build the dashboards people will actually use. Grafana ships with cluster-level dashboards from the chart. Add one focused per-service dashboard showing request rate, error rate, latency and saturation. Keep it to one screen so it is readable during an incident.
- Configure alerts at the symptom level. Alert on things users feel: error-rate spikes, latency above an agreed threshold, pods in CrashLoopBackOff, nodes with DiskPressure, and persistent volume usage. Route alerts through Alertmanager to email, chat or an on-call tool. Set a sensible
for:duration so a single blip does not page anyone. - Set retention and resource limits. Define how long logs and metrics are kept, size persistent volumes accordingly, and set CPU and memory requests and limits on every monitoring pod. Unbounded Prometheus or log storage is the most common way this stack takes down the cluster it is supposed to watch.
- Test the pipeline. Delete a pod and watch its logs still be searchable. Kill a deployment's readiness probe and confirm an alert fires. A monitoring stack nobody has failure-tested is a guess.
Common Mistakes
Logging only after an incident: if the collector was never installed, the evidence is gone. Retaining data forever without limits, which fills disks and causes evictions. Alerting on causes (CPU at 80%) instead of symptoms (latency users notice), which produces noise people learn to ignore. Scraping every namespace including high-cardinality test traffic, inflating Prometheus memory. Running Prometheus on the same node pool as the workloads it watches, so a node failure blinds you exactly when you need visibility. Forgetting that pod names change on every restart, so dashboards keyed on pod name break constantly — aggregate by workload or deployment label instead.
Tips
Label consistently across logs and metrics (app, version, environment) so you can pivot from a spike to the matching log lines. Keep a single timestamp format everywhere. Use kubectl logs --previous to read the logs of a container that just crashed. Export dashboards and alert rules as YAML in version control rather than clicking them into Grafana, so they survive a cluster rebuild. Start with a handful of alerts that page someone and a broader set that only goes to a dashboard or chat channel. If your cloud provider offers managed logging and metrics, weigh the operational savings — self-hosting this stack is a real maintenance commitment.
Troubleshooting
Logs are missing for one pod: check the collector pod on that node is running, confirm the container writes to stdout and not only a file, and inspect the collector's own logs for parse or delivery errors. Metrics targets show as down: open the Prometheus UI's targets page, read the error (often a wrong port, a missing ServiceMonitor, or a network policy blocking scrape traffic), and check the app's /metrics endpoint from inside the cluster. Grafana shows no data: verify the data source URL points at the in-cluster Prometheus service, and that the time range and dashboard variables are set to a namespace that exists. Alerts never arrive: confirm Alertmanager is receiving from Prometheus, then check its receivers and whether the alert is in a silenced state. Everything is slow: look at kubectl top nodes — the monitoring stack itself is a likely culprit.
If that did not work: remove the Helm releases and reinstall one component at a time, verifying each with the built-in checks from step one, so you know exactly which piece broke.
Frequently Asked Questions
Do I need both logging and monitoring?
Yes. Metrics tell you something is wrong and roughly where; logs tell you why. Trying to answer root-cause questions from metrics alone is slow and imprecise.
Can I use kubectl logs as my only logging?
Only for live debugging. Logs disappear when a pod is deleted, so nothing survives a restart, reschedule or node failure.
Does Kubernetes store logs on the node?
The container runtime keeps log files on the node and rotates them, but they are not durable or searchable across the cluster — that is exactly what the agent and backend solve.
What is the difference between a ServiceMonitor and scrape annotations?
Both tell Prometheus what to scrape. ServiceMonitors are custom resources managed alongside the app; annotations are simpler but less flexible. Use one consistently.
How long should I keep metrics and logs?
It depends on your incident and audit needs and your storage budget. Pick a period, measure the storage it consumes, and adjust; leaving it undefined always ends in a full disk.