Kubernetes is a container orchestration platform that provides a mechanism to manage the resources of containers in the cluster. That mechanism is known as "Requests and Limits".
Requests and limits play a key role not only in resource management but also in applications stability, capacity planning, scheduling the resources (i.e., on which node the pod will be running).
In this session we will cover:
- A quick review of Containers, Docker, and Kubernetes.
- Containers resource management in Kubernetes.
- Containers resource types in Kubernetes.
- 3 different ways to set requests and limits.
- The difference between capacity and allocatable resources.
- Tips and recap.
Scanning the Internet for External Cloud Exposures via SSL Certs
Kubernetes Requests and Limits
1. Kubernetes Requests and Limits
Managing containers resources in Kubernetes
Ahmed AbouZaid, DevOps Engineer, Camunda
23.06.2021
2. 2
Ahmed AbouZaid
A passionate DevOps engineer, Cloud/Kubernetes
specialist, Free/Open source geek, and an author.
I believe in self CI/CD
(Continuous Improvements/Development),
also that "the whole is greater than the sum of its parts".
DevOps transformation, automation, data, and metrics
are my preferred areas. And I like to help both
businesses and people to grow.
Find me at:
tech.aabouzaid.com | linkedin.com/in/aabouzaid
About
September 2017, who says a penguin can't fly?
3. 3
Agenda
• Overview
• Containers, Docker, and Kubernetes
• Containers resource management
• Containers resource types
• Setting requests and limits
• Capacity and allocatable resources
• Tips and recap
5. 5
Overview
Kubernetes is a container orchestration platform that provides a mechanism to
manage the resources of containers in the cluster.
That mechanism plays a role not only in managing the cluster resources but also
in scheduling the resources (i.e., on which node the pod will be running).
In this session, first, we will have a look at units of the Kubernetes cluster, then
how containers resource are managed, what kind of resources are managed,
then the difference between the cluster capacity and allocatable resources, then
requests and limits the scope, and finally tips and recap.
7. 7
Containers, Docker, and Kubernetes
Containers
Technology for packaging an application
along with its runtime dependencies
Docker
Docker is the de facto standard to build
and share containerized apps
Kubernetes
A cloud-native platform to manage and
orchestrate containers workloads
8. 8
Containers, Docker, and Kubernetes (continued)
Cluster
A collection of nodes that are grouped
together to provide resources sharing
and workload balancing
Node
The unit of computing in Kubernetes,
easily thought of as one individual machine
which runs Pods.
Pod
A logical host with collection of one
or more container, and it is the smallest
computing unit in Kubernetes Image source:
Kubernetes docs - Managing Resources for Containers
10. 10
Containers resource management
• Kubernetes allows to optionally set
how much resources a container needs
via “Requests and Limits”.
• The most common resources to specify
are CPU and memory.
• Requests and limits play a key role not
only in resource management but also
for stability and capacity planning.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: myimage
resources:
requests:
cpu: "1"
memory: "64Mi"
ephemeral-storage: "20Gi"
limits:
cpu: "2"
memory: "128Mi"
ephemeral-storage: "50Gi"
11. 11
Containers resource management (continued)
Image source:
Learnk8s - Setting the right requests and limits in Kubernetes
What are requests and limits?
Requests and limits are the mechanisms
Kubernetes uses to control containers resources
such as CPU, memory, and ephemeral storage.
1. Requests: resources that container is guaranteed
to get by Kubernetes. It’s the minimum amount of
resources that are needed to work.
2. Limits: resources that container should not pass.
The container is only allowed to go up to that
threshold, otherwise Kubernetes will restrict it.
13. 13
Containers resource types (continued)
There are 3 core resources that could be configured via requests and limits:
(those resources used from underneath nodes)
• CPU
Measured in 1 vCPU/Core; thus, half of CPU core represented as “0.5”
which also equivalent to “500m”.
• Memory
Measured in bytes and can expressed as a plain integer or using suffixes, the
following are same value: “128974848”, “129M”, “123Mi”.
• Local ephemeral storage (e.g. ‘emptyDir’ volume)
Measured in bytes and can expressed as a plain integer or using suffixes, the
following are same value: “128974848”, “129M”, “123Mi”.
14. 14
Containers resource types (continued)
What happens if a container
exceeded the configured limits?
• CPU
Kubernetes will enter “overcommit”
state and will just “throttle” (limit)
the container’s usage.
• Memory or ephemeral storage
Kubernetes will “evict” (kill)
the container’s pod and recreate it. Image source:
ITNEXT - Easy and Fast Adjustment of Kubernetes CPU and Memory
16. 16
Kubernetes requests and limits could be
specified in 3 ways:
1. Container settings (Pod level)
Each container in a pod able to
configures their own requests
and limits.
Setting requests and limits
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: myimage
resources:
requests:
cpu: "1"
memory: "64Mi"
ephemeral-storage: "20Gi"
limits:
cpu: "2"
memory: "128Mi"
ephemeral-storage: "50Gi"
17. 17
2. LimitRange (Namespace level)
Configure resources for “every”
individual container in a namespace.
It helps to set default, min, and max
resources in the namespace.
Setting requests and limits (continued)
apiVersion: v1
kind: LimitRange
metadata:
name: dev-ns-limits
namespace: default
spec:
limits:
- type: Container
defaultRequest:
cpu: "1"
18. 18
3. ResourceQuota (Namespace level)
Configure the “whole” resources in
a namespace. For example, setting
max CPU to “2” means all containers
“combined” in the namespace cannot
exceed 2 cores (1 container gets 2
cores, 2 containers get 1 core each, etc).
Setting requests and limits (continued)
apiVersion: v1
kind: ResourceQuota
metadata:
name: dev-team-quota
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
20. 20
Capacity and allocatable resources
The maximum resources available for
any container is the maximum resources
on a single Kubernetes node.
However, not all Kubernetes node resources
is available for the pods.
Part of the node resources are saved for
Kubernetes agent essential components,
operating system, and eviction threshold.
• Capacity: total node resources.
• Allocatable: resources available for Pods.
Allocatable resources vary between cloud providers
but usually they are around 75% of the total capacity
Image source:
Learnk8s - Allocatable memory and CPU in Kubernetes Nodes
22. 22
Tips and recap
• Requests and limits play a key role not only in resource management
but also applications stability and capacity planning.
• Requests cannot configured to be more than limits.
• Requests and limits cannot be greater than the biggest Kubernetes node.
• Not all resources in Kubernetes nodes can be used to run Pods
you get in average about 75% of the total nodes resources.
• Pods with no requests and limits are more likely to be evicted first.
• When you set requests and limits for the first time, start with a small value
then adjust by monitoring your application usage for accurate values.
• Inaccurate requests and limits is waste of money and resources!
24. 24
References
• What is a Kubernetes pod?
redhat.com/en/topics/containers/what-is-kubernetes-pod
• Managing Resources for Containers
kubernetes.io/docs/concepts/configuration/manage-resources-containers
• Kubernetes best practices: Resource requests and limits
cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-reso
urce-requests-and-limits
• Easy and Fast Adjustment of Kubernetes CPU and Memory
itnext.io/easy-and-fast-adjustment-of-kubernetes-cpu-and-memory-709394cc2cb1
• Setting the right requests and limits in Kubernetes
learnk8s.io/setting-cpu-memory-limits-requests
• Allocatable memory and CPU in Kubernetes Nodes
learnk8s.io/allocatable-resources