Allocating resources for nodes in an OKD cluster

    CPU and memory resources reserved for node components in OKD are based on two node settings:

    If a flag is not set, the defaults are used. If none of the flags are set, the allocated resource is set to the node’s capacity as it was before the introduction of allocatable resources.

    An allocated amount of a resource is computed based on the following formula:

    If Allocatable is negative, it is set to 0.

    Each node reports the system resources that are used by the container runtime and kubelet. To simplify configuring the system-reserved parameter, view the resource use for the node by using the node summary API. The node summary is available at /api/v1/nodes/<node>/proxy/stats/summary.

    The node is able to limit the total amount of resources that pods can consume based on the configured allocatable value. This feature significantly improves the reliability of the node by preventing pods from using CPU and memory resources that are needed by system services such as the container runtime and node agent. To improve node reliability, administrators should reserve resources based on a target for resource use.

    The node enforces resource constraints by using a new cgroup hierarchy that enforces quality of service. All pods are launched in a dedicated cgroup hierarchy that is separate from system daemons.

    Enforcing system-reserved limits can prevent critical system services from receiving CPU and memory resources. As a result, a critical system service can be ended by the out-of-memory killer. The recommendation is to enforce system-reserved only if you have profiled the nodes exhaustively to determine precise estimates and you are confident that critical system services can recover if any process in that group is ended by the out-of-memory killer.

    If a node is under memory pressure, it can impact the entire node and all pods running on the node. For example, a system daemon that uses more than its reserved amount of memory can trigger an out-of-memory event. To avoid or reduce the probability of system out-of-memory events, the node provides out-of-resource handling.

    You can reserve some memory using the --eviction-hard flag. The node attempts to evict pods whenever memory availability on the node drops below the absolute value or percentage. If system daemons do not exist on a node, pods are limited to the memory . For this reason, resources set aside as a buffer for eviction before reaching out of memory conditions are not available for pods.

    The following is an example to illustrate the impact of node allocatable for memory:

    • Node capacity is 32Gi

    • --system-reserved is 3Gi

    • --eviction-hard is set to 100Mi.

    For this node, the effective node allocatable value is 28.9Gi. If the node and system components use all their reservation, the memory available for pods is 28.9Gi, and kubelet evicts pods when it exceeds this threshold.

    If you enforce node allocatable, 28.9Gi, with top-level cgroups, then pods can never exceed 28.9Gi. Evictions are not performed unless system daemons consume more than 3.1Gi of memory.

    If system daemons do not use up all their reservation, with the above example, pods would face memcg OOM kills from their bounding cgroup before node evictions kick in. To better enforce QoS under this situation, the node applies the hard eviction thresholds to the top-level cgroup for all pods to be Node Allocatable + Eviction Hard Thresholds.

    If system daemons do not use up all their reservation, the node will evict pods whenever they consume more than 28.9Gi of memory. If eviction does not occur in time, a pod will be OOM killed if pods consume 29Gi of memory.

    The scheduler uses the value of node.Status.Allocatable instead of node.Status.Capacity to decide if a node will become a candidate for pod scheduling.

    By default, the node will report its machine capacity as fully schedulable by the cluster.

    Configuring allocated resources for nodes

    As an administrator, you can set these using a custom resource (CR) through a set of <resource_type>=<resource_quantity> pairs (e.g., cpu=200m,memory=512Mi).

    Prerequisites

    1. Obtain the label associated with the static MachineConfigPool CRD for the type of node you want to configure. Perform one of the following steps:

      1. View the Machine Config Pool:

        1. $ oc describe machineconfigpool <name>

        For example:

        1. $ oc describe machineconfigpool worker

        Example output

      2. If the label is not present, add a key/value pair:

        1. $ oc label machineconfigpool worker custom-kubelet=small-pods

    Procedure

    1. Create a custom resource (CR) for your configuration change.

      Sample configuration for a resource allocation CR

      1. kind: KubeletConfig
      2. metadata:
      3. name: set-allocatable (1)
      4. spec:
      5. machineConfigPoolSelector:
      6. matchLabels:
      7. custom-kubelet: small-pods (2)
      8. kubeletConfig:
      9. systemReserved:
      10. memory: 1Gi