K8s Memory Manager
Requriement
Your Kubernetes server must be at or later than version v1.21. To check the version, enter kubectl version
.
To align memory resources with other requested resources in a Pod Spec:
- the CPU Manager should be enabled and proper CPU Manager policy should be configured on a Node. See control CPU Management Policies;
- the Topology Manager should be enabled and proper Topology Manager policy should be configured on a Node. See control Topology Management Policies.
Starting from v1.22, the Memory Manager is enabled by default through MemoryManager
feature gate.
Preceding v1.22, the kubelet
must be started with the following flag:
--feature-gates=MemoryManager=true
in order to enable the Memory Manager feature
How Memory Manager Operates?
During this process, the Memory Manager updates its internal counters stored in Node Map and Memory Maps to manage guaranteed memory allocation.
The Memory Manager updates the Node Map during the startup and runtime as follows.
Runtime
Important topic in the context of Memory Manager operation is the management of NUMA groups. Each time pod’s memory request is in excess of single NUMA node capacity(当POD要求的内存,大于单 NUMA Node容量时), the Memory Manager attempts to create a group that comprises several NUMA nodes and features extend memory capacity. The problem has been solved as elaborated(详细说明) in Memory Manager KEP: How to enable the guaranteed memory allocation over many NUMA nodes?. Also, reference Memory Manager KEP: Simulation - how the Memory Manager works? (by examples) illustrates how the management of groups occurs.
Manager configuration
Other Managers should be first pre-configured (section Pre-configuration). Next, the Memory Manger feature should be enabled (section Enable the Memory Manager feature) and be run with Static
policy (section Static policy). Optionally, some amount of memory can be reserved for system or kubelet processes to increase node stability (section Reserved memory flag).
Policies
Memory Manager supports two policies. You can select a policy via a kubelet
flag --memory-manager-policy
.
Two policies can be selected:
None
(default)Static
Reserved memory flag
Troubleshooting
kubelet state file
state file in /var/lib/kubelet/memory_manager_state:
|
|
Ref
https://kubernetes.io/docs/tasks/administer-cluster/memory-manager/