Easy and Fast Adjustment of Kubernetes CPU and Memory
Assigning and managing CPU and memory resources in the Kubernetes can be tricky and easy at the same time.
Join the DZone community and get the full member experience.Join For Free
Assigning and managing CPU and memory resources in the Kubernetes can be tricky and easy at the same time. Having done this task for numerous customers, I have decided to create a framework zone. I will show you what Kubernetes resources and limits are and how to manage them.
The framework contains the following steps.
- Infographic Guide shows what algorithms to follow to determine and assign the resources and limits.
- Code templates allow applying those algorithms with minimal adaptation.
- Algorithms and tools to gather the metrics about resource consumption and set up the limits.
- Links to the official documentation where you can quickly grab some examples and read more detailed information.
What This Article Doesn't Contain
My goal here is simplicity. So you won't find detailed descriptions of how resources, limit ranges, and quotas work. There are plentiful articles written about it, as well as Kubernetes thorough documentation. Instead, here you will find information on how to quickly start adjusting Kubernetes resources in your projects.
Basics Guide on CPU and Memory Resources
Two cheat-sheets explaining what resources are in terms of Kubernetes, measurement units, the resource state workflow, and some rules on how to apply it.
CPU and Memory Measurement Units
Be aware that the CPU calculation formula is not applied to every setup or project. It is used as a starting point in the process of detecting and assigning the resource and limits.
Kubernetes deployment YAML template includes container, resource, and limits definitions.
More detailed information and code snippets:
- Kubernetes.io. Assign memory resource guide.
- Kubernetes.io. Assign CPU resource guide.
- Kubernetes best practices resource requests and limits
- Azure Kubernetes Services. Developer best practices resource-management
Resources Quota Guide
Two quota templates that contain quotas definition for persistent volume claims and resources in the backed namespace.
You can use the
kubectl apply command to set the quota constraints for a namespace.
Detailed explanation of quotas, metrics, and how to use quota expressions and code samples.
Limit Ranges Guide
Two limit range code templates to limit CPU and Memory resources for the containers and to limit the storage (Persistent Volume Claim). To set this constraint, you can also use
kubectl apply -f path/to/file.yaml -n namespace.
More detailed information and code snippets.
- Manage resources. Cpu default namespace
- Kubernetes io. Limit storage consumption
- Kubernetes io. Limit ranges
Tools and Frameworks that Helps with Resource and Limits Routine
- Popeye scans your cluster for potential issues with configuration, resources, and network holes and generates detailed reports with all issues.
- Goldilocks scans pods for resource limits and creates reports with recommended resources.
- Kube-advisor simple tool, from Azure team, that scans pods for missing resource and limits requests.
- K9s+benchmark — provides a command-line interface (CLI) that allows you to easily manage, monitor, and even benchmark your cluster in
your favorite terminal software
- Setup Resource Requests. Get information about CPU and Memory usage of specific Application/Container.
- Setup Resource Limits. Setup Resource Requests. Run a load test to detect CPU and Memory of a container under the high load..
- Monitor containers CPU and Memory usage.
- Monitor persistent storage usage.
- Check if you can apply resource limit using limit ranges (if you have similar containers, storage set up)
- Apply limit range for storage if needed. Or use Quota (it is not recommended to apply Quota for production environment)
I have shared with you the framework I created and use on a daily basis while working with the Kubernetes requests and limits. I hope you will find it useful. Any ideas on how to make it better?
Please feel free to share your feedback and suggestions in the comments.
Published at DZone with permission of Boris Zaikin. See the original article here.
Opinions expressed by DZone contributors are their own.