Skip to main content

CPU units on your cluster

CPU units measure CPU by benchmark, not by core count. 500 units are one baseline core. A fast core gives more units than a slow core. When a pod requests units, it gets the same compute on every machine type that Multicloud starts for your pool.

This page tells you how to use CPU units in your Multicloud cluster.

What you must know first

  • CPU units are optional. Pods that request cpu work as before.
  • Pods with cpu and pods with CPU units can run on the same node.
  • You turn on CPU units for one namespace at a time, with a label.
  • In a namespace with the label, a pod uses CPU units only when it requests them.
  • CPU units apply per container. A sidecar that requests cpu keeps its cpu request, and Multicloud sizes nodes for it.

Turn on CPU units for a namespace

Add the label multicloud.io/cpu-units=enabled to the namespace:

kubectl label namespace shop multicloud.io/cpu-units=enabled

Or set the label in the namespace manifest:

apiVersion: v1
kind: Namespace
metadata:
  name: shop
  labels:
    multicloud.io/cpu-units: enabled

You cannot turn on CPU units in these namespaces: kube-system, kube-public, kube-node-lease, liqo, arc-system, argocd. Multicloud uses them for the cluster itself.

The door-ci namespace of a CI pool has the label already.

Request CPU units in a pod

Request the resource multicloud.io/cpu-units in each container that must use CPU units. Set the same value as the request and the limit. Kubernetes requires equal values for an extended resource. Do not set cpu in that container.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: shop
spec:
  replicas: 2
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
      annotations:
        # Optional: the pod may burst up to 2000 units when the node has free CPU.
        multicloud.io/cpu-units-limit: "2000"
    spec:
      containers:
        - name: app
          image: ghcr.io/example/web:1.4.2
          resources:
            requests:
              multicloud.io/cpu-units: "1000"
              memory: 512Mi
            limits:
              multicloud.io/cpu-units: "1000"
              memory: 512Mi
Field Where Meaning
multicloud.io/cpu-units container requests and limits The guaranteed CPU of the container, in units. 1000 units are two baseline cores.
multicloud.io/cpu-units-limit pod annotation Optional. The most units the whole pod can use. If you do not set it, the pod has no CPU limit: it can use idle CPU on the node, and pods with larger requests get CPU first when the node is busy. This is the standard Kubernetes behavior of a CPU request without a CPU limit. A ResourceQuota on limits.cpu rejects such a pod, so set the annotation in a namespace that has one.
multicloud.io/cpu-units-startup pod annotation Optional. The units the pod gets until its containers have started, for a slow start (for example a JVM).

What Multicloud does with the pod

  1. When you create the pod, Multicloud adds a cpu request to each container that requests units. Multicloud adds a cpu limit only when the pod has the multicloud.io/cpu-units-limit annotation.
  2. Kubernetes puts the pod on a node that has free units.
  3. Multicloud then changes the cpu request of the running pod to the real value for that node. The pod does not restart.

Do not edit the cpu values that Multicloud adds.

If Kubernetes refuses the pod

You can see this error:

cpu-units: a container requests multicloud.io/cpu-units but has no cpu request, so the cpu-units
webhook did not admit the pod. Label the namespace with multicloud.io/cpu-units=enabled, or retry
when the webhook (Deployment cpu-units in kube-system) is ready.

The container requests units, but Multicloud did not add its cpu request. Kubernetes refuses the pod, because without a cpu request the container gets no guaranteed CPU.

  1. Check the namespace label:

    kubectl get namespace shop --show-labels
    
  2. If the label multicloud.io/cpu-units=enabled is not there, add it. Then create the pod again.

  3. If the label is there, the CPU units service may be starting (for example, after the cluster wakes up). Wait one minute. Then create the pod again. A Deployment or a Job creates the pod again by itself.

A pool that scales to zero

The CPU units service runs on the nodes of your cluster. When your pool has no node, the service cannot add the cpu request, so Kubernetes refuses a pod that requests only units. If no other pod is waiting, Multicloud does not start a node for it.

If your pool can scale to zero and its workloads request only units, add a small cpu request beside the units in each container:

resources:
  requests:
    multicloud.io/cpu-units: "1000"
    cpu: 10m
    memory: 512Mi
  limits:
    multicloud.io/cpu-units: "1000"
    memory: 512Mi

Kubernetes then accepts the pod at all times, and Multicloud starts a node for it. Multicloud keeps your cpu request at admission and changes it to the real value when the pod runs.

A pod stays Pending

If no node has enough free units, the pod stays Pending. Multicloud then starts a node that has enough units. Pods that request cpu use CPU on the same nodes. This leaves fewer units for new pods on those nodes.

Turn off CPU units for a namespace

Remove the label:

kubectl label namespace shop multicloud.io/cpu-units-

Running pods do not change. Before you create new pods in that namespace, change them to request cpu instead of multicloud.io/cpu-units, or Kubernetes refuses them.