While troubleshooting Kubernetes issues, I often noticed that some applications, due to bugs or misconfigurations, consume all the available resources on a worker node. This impacts the performance of other applications and pods running on the same node, leading to instability in the cluster.
One common culprit is the lack of properly defined resource requests
and limits
for pods. This motivated me to automate the process of identifying pods missing resource definitions, analyze their usage, and recommend optimal configurations.
Defining proper CPU, memory requests and limits for pods can prevent crashes and reduce resource wastage. However, identifying pods missing resource definitions can be a daunting task. This is where Pod-Resource-Checker steps in.
You can also refer previous blog posts which explains the internals of defining CPU/Memory resources for the applications:
- Understanding CPU Requests and Limits in Kubernetes: What “1 CPU” Really Means?
- How Kubernetes Manages Pod Memory Using cgroups: Requests, Limits, and OOM Handling
What is Pod-Resource-Checker
Pod-Resource-Checker is a simple tool designed to:
- Identify Pods Without Resource Definitions: Quickly find pods missing CPU and memory requests and limits.
- Analyze Resource Utilization: Retrieve real-time metrics for current CPU and memory usage(from metrics server).
- Recommend Optimized Resources: Generate suggestions for resource requests and limits with a user-defined buffer.
- Output Ready-to-Use YAML: Provide configuration snippets to apply resource changes.
- Optional In-Place Updates: Directly update resource definitions(for test environments).
Why Use Pod-Resource-Checker?
- Prevent Over/Under-Provisioning: Avoid crashes and resource wastage by ensuring pods have proper resource definitions.
- Simplify Resource Auditing: Quickly scan clusters for missing resource configurations.
- Save Time: Automate resource analysis with actionable suggestions.
- Customizable: Adjust buffer percentages to accommodate your workload’s needs.
Getting Started
Project Repository:
Run the Tool:
Standalone application:
- Analyze all namespaces:
export KUBECONFIG=/root/kubeconfig
./pod_resources
- Focus on a specific namespace with buffer-percentage:
./pod_resources --namespace default --buffer-percent 50
- Scanning and inplace-update the pods from the namespace:
./pod_resources --namespace default --inplace-update
Deploy in Kubernetes:
- Use the Kubernetes Job YAML to analyze clusters:
export KUBECONFIG=/root/kubeconfig
kubectl apply -f https://raw.githubusercontent.com/pratik705/pod-resource-checker/refs/heads/main/k8s_manifest.yaml
Example Output
# export KUBECONFIG=/root/kubeconfig
# ./pod_resources --namespace wordpress --buffer-percent 20
OR
# kubectl apply -f https://raw.githubusercontent.com/pratik705/pod-resource-checker/refs/heads/main/k8s_manifest.yaml
# kubectl logs job/pod-resources-checker
Use Responsibly
While Pod-Resource-Checker simplifies resource management, always test changes in a development or staging environment before applying them to production.
Check out Pod-Resource-Checker on GitHub to start optimizing your Kubernetes clusters today!