Kubernetes Monitoring with kubectl: Pods, Nodes & Resources
Kubernetes Monitoring with kubectl: Pods, Nodes & Resources
Getting "No resources found" from kubectl get pods? See kubectl get pods: No resources found - causes and fixes.
Kubernetes monitoring is essential for maintaining reliable containerized applications and ensuring optimal cluster performance. This comprehensive guide covers everything you need to know about monitoring Kubernetes clusters, pods, and container orchestration.
For related container topics, see Docker Container Monitoring. For troubleshooting Kubernetes issues, see Docker Container Crash Restart Loop.
Why Kubernetes Monitoring Matters
Kubernetes clusters manage complex containerized applications. Without proper monitoring, pod failures, resource exhaustion, and cluster issues can cause application downtime and poor performance.
Effective Kubernetes monitoring enables you to:
- Track pod status and health
- Monitor cluster resource usage
- Detect pod failures and restarts
- Ensure application availability
- Optimize resource allocation
- Maintain cluster reliability
Key Kubernetes Metrics to Monitor
Pod Metrics
- Pod Status: Running, pending, failed, or succeeded
- Pod Restart Count: Number of pod restarts
- Pod Resource Usage: CPU and memory consumption
- Pod Availability: Pod uptime percentage
Cluster Metrics
- Node Status: Node availability and health
- Cluster Resource Usage: Overall CPU and memory usage
- Namespace Resource Usage: Resource usage per namespace
- Cluster Capacity: Available cluster resources
Application Metrics
- Deployment Status: Deployment availability
- Service Availability: Service endpoint availability
- Replica Count: Number of running replicas
- Application Health: Application health check status
Method 1: Monitor Kubernetes with kubectl
Check Pod Status
# List all pods
kubectl get pods
# Get pod status details
kubectl get pods -o wide
# Check pod status in namespace
kubectl get pods -n <namespace>
# Get pod details
kubectl describe pod <pod-name>
# Check pod logs
kubectl logs <pod-name>
Monitor Pod Resources
# Get pod resource usage
kubectl top pods
# Get pod resource usage in namespace
kubectl top pods -n <namespace>
# Get node resource usage
kubectl top nodes
# Get detailed resource metrics
kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods
Check Cluster Status
# Get cluster nodes
kubectl get nodes
# Get node details
kubectl describe node <node-name>
# Check cluster components
kubectl get componentstatuses
# Get cluster events
kubectl get events --sort-by='.lastTimestamp'
Method 2: Monitor Kubernetes with Kubernetes API
Query Kubernetes Metrics API
# Get pod metrics
kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods
# Get node metrics
kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes
# Get namespace metrics
kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespaces/<namespace>/pods
Method 3: Automated Kubernetes Monitoring with Zuzia.app
Manual checks work while you are looking. To keep running them without you, Zuzia uses its agent and scheduled tasks.
How it works in Zuzia
- Install the Zuzia agent on the server with one command. CPU, RAM, disk, load and network metrics start reporting on their own, with alerts on a threshold, on drift from the server's normal, or on a disk fill-up forecast.
- Save the commands from this guide as a scheduled task and choose how often it runs, from every minute to once a year. The agent runs it on every host you pick.
- If a command fails, you get an alert right away by email, Slack, Discord, push (through your Pushover account) or SMS (through your Vonage account).
- The output of every run is kept, so you can look back at what changed. On paid plans, AI can read the output and alert you only when it spots a problem.
Setting it up
- Add the server in the Zuzia dashboard and install the agent.
- Create a scheduled task with the check commands below, then choose the hosts and how often it runs.
- Choose your notification channels. Turn on maintenance mode during planned work so it doesn't trigger alerts.
Best Practices for Kubernetes Monitoring
1. Monitor All Pods Continuously
- Track pod status for all namespaces
- Monitor pod restart counts
- Alert when pods fail
- Ensure sufficient pod replicas
2. Monitor Cluster Resources
- Track cluster CPU and memory usage
- Monitor node availability
- Alert when resources are exhausted
- Plan cluster capacity upgrades
3. Set Up Comprehensive Alerts
- Configure alerts for pod failures
- Set up alerts for resource exhaustion
- Monitor cluster health
- Alert on deployment issues
4. Track Kubernetes Trends
- Review cluster performance trends weekly
- Identify pod failure patterns
- Optimize resource allocation based on trends
- Correlate pod issues with application changes
5. Monitor Application Health
- Track application health checks
- Monitor service availability
- Ensure deployment success
- Verify replica counts
Troubleshooting Kubernetes Issues
Step 1: Identify Kubernetes Problems
When Kubernetes issues occur:
Check Pod Status:
- Review pod status and events
- Check pod logs for errors
- Identify failed pods
Monitor Cluster Resources:
- Check cluster resource usage
- Review node availability
- Identify resource bottlenecks
Review Cluster Events:
- Check cluster events
- Identify error patterns
- Review deployment issues
Step 2: Resolve Kubernetes Issues
Based on investigation:
Fix Pod Issues:
- Restart failed pods
- Fix application bugs
- Update pod configuration
Optimize Cluster Resources:
- Scale cluster if needed
- Optimize resource requests
- Implement resource limits
Improve Cluster Monitoring:
- Adjust monitoring thresholds
- Improve pod health detection
- Update monitoring procedures
FAQ: Common Questions About Kubernetes Monitoring
How often should I check Kubernetes clusters?
For production Kubernetes clusters, continuous automated monitoring is essential. Zuzia.app can check Kubernetes status every few minutes, storing historical data and alerting you when issues are detected.
What should I monitor in Kubernetes?
Monitor pod status, pod resource usage, cluster resource usage, node availability, deployment status, and application health. Focus on metrics that impact application availability and performance.
How do I monitor Kubernetes across multiple clusters?
Zuzia.app allows you to monitor Kubernetes clusters across multiple environments from one centralized dashboard. Each cluster executes monitoring commands independently, and all results are stored for centralized analysis.
Can Kubernetes monitoring impact cluster performance?
Kubernetes monitoring commands have minimal impact on cluster performance when done correctly. Use appropriate monitoring frequency and ensure monitoring doesn't interfere with application workloads.
Related guides, recipes, and problems
Related guides
guides--monitoring-docker-containers-production.mdguides--server-resource-monitoring-complete-guide.md
Related recipes
recipes--monitor-kubernetes-pod-status-resources.mdrecipes--monitor-docker-container-resource-usage.md
Related problems
problems--docker-container-crash-restart-loop.mdproblems--service-keeps-stopping-restarting.md