Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Monitoring Kubernetes Kubernetes: From Zero to Production Module 8 - Monitoring and Troubleshooting

Logs and Monitoring in Kubernetes

Reviewed & accurate
AI Summary

What You Will Learn

Intermediate

  • How to view Pod logs
  • Log aggregation patterns
  • Prometheus + Grafana for monitoring
Terminalbash
# View Pod logs
kubectl logs my-pod

# Follow logs (tail -f)
kubectl logs -f my-pod

# Last 50 lines
kubectl logs --tail=50 my-pod

# Previous container logs (if Pod restarted)
kubectl logs --previous my-pod

# Logs from all Pods in a Deployment
kubectl logs -f deployment/my-app --all-containers
Logs are per-container
K8s does not aggregate logs. Each container's stdout/stderr is stored on the node. For production, use a log aggregator: Fluentd -> Elasticsearch -> Kibana (EFK stack).

Monitoring with Prometheus + Grafana

Terminalbash
# Install Prometheus + Grafana on minikube
minikube addons enable metrics-server

# Or use kube-prometheus-stack (Helm)
helm install monitoring prometheus-community/kube-prometheus-stack

# Port-forward Grafana
kubectl port-forward svc/monitoring-grafana 3000:80
# Open http://localhost:3000 (admin/prom-operator)

Practical Exercise

Run: kubectl logs for a running Pod
Run: kubectl logs -f (follow)
Install metrics-server: minikube addons enable metrics-server
Run: kubectl top pods (see CPU/memory usage)
Install Prometheus + Grafana with Helm

Key Takeaways

  • kubectl logs: view container stdout/stderr.
  • kubectl logs -f: follow logs. --previous: before crash.
  • For production: use Fluentd + Elasticsearch + Kibana.
  • Prometheus: scrape metrics. Grafana: visualize.
  • kubectl top: see CPU/memory per Pod.
Previously: Module 7 covered security.
Today: You learned: View logs and monitor your cluster.
Next: Lesson 41 covers debugging.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments