Prompt
how to monitor kubernetes pods and containers
Latest observation
To monitor Kubernetes pods and containers, you typically combine metrics, logs, and alerts. Here’s a practical approach.
1) Basic built-in commands
These are good for quick checks:
kubectl get pods -A
kubectl describe pod <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace>
kubectl logs -f <pod-name> -n <namespace>
kubectl top pod -A
kubectl top node
Use these to check:
- pod status (
Running,CrashLoopBackOff,Pending, etc.) - events and scheduling issues
- container logs
- CPU/memory usage
2) Monitor resource usage with Metrics Server
Install metrics-server if you want kubectl top to work.
It provides:
- CPU and memory usage for pods and nodes
- basic autoscaling inputs
Without it, Kubernetes won’t have live resource metrics.
3) Use Prometheus + Grafana for full monitoring
This is the most common setup.
Prometheus
Collects metrics from:
- kubelet
- cAdvisor
- Kubernetes API server
- node exporters
- application metrics
Grafana
Used to visualize dashboards for:
- pod CPU/memory
- node health
- restart counts
- container restarts
- network I/O
- disk usage
A common install option is kube-prometheus-stack via Helm.
4) Use logging tools
For pod/container logs, use centralized logging such as:
- ELK/EFK stack (Elasticsearch + Fluentd/Fluent Bit + Kibana)
- Loki + Promtail + Grafana
- Cloud logging services:
- AWS CloudWatch
- Azure Monitor
- Google Cloud Logging
This helps you search logs across many pods and namespaces.
5) Set up alerts
Alerts notify you when something is wrong:
- pod crash loops
- high CPU/memory
- node unavailable
- too many restarts
- failed liveness/readiness probes
- disk pressure / OOMKills
Prometheus Alertmanager is commonly used for this.
6) Check health probes
Add Kubernetes probes to your workloads:
- livenessProbe: restart container if unhealthy
- readinessProbe: remove pod from service if not ready
- startupProbe: allow slow-starting apps more time
Example:
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
7) Use monitoring agents / APM for apps
For deeper application monitoring, use:
- Datadog
- New Relic
- Dynatrace
- Elastic APM
- OpenTelemetry
These can show:
- request latency
- error rates
- traces
- app-level metrics
- container and pod visibility
8) Useful things to track
At minimum, monitor:
- Pod status and restarts
- CPU/memory usage
- Node resource usage
- Container exits / OOMKilled
- Deployment rollout status
- Failed probes
- Network errors
- Disk pressure
- Pod scheduling failures
9) Example monitoring stack
A common Kubernetes monitoring setup:
- Metrics Server for basic resource commands
- Prometheus for metrics collection
- Grafana for dashboards
- Alertmanager for alerts
- Loki or EFK for logs
10) Quick recommendation
If you want a simple but solid setup:
- Install metrics-server
- Install kube-prometheus-stack
- Add Loki for logs
- Configure alerts for restarts, high CPU/memory, and node issues
If you want, I can also give you:
- a step-by-step install guide for Prometheus/Grafana on Kubernetes
- a Helm-based setup
- or a minimal monitoring checklist for production