Magalix Runs Kubernetes on Autopilot!

Guides    Discussions

Defining Resources Requests & Limits

This topic provides details on how to define resources requests and limits - 1.5 min read

Magalix AI collects resources utilization and KPI metrics. It collects CPU, memory, and I/O usage patterns at set intervals. Metrics and behavioral analysis take place at the level of containers, services, and app. Our proprietary algorithms simplify and aggregate these metrics to use them as different features fed into the machine learning models.

While your Kubernetes cluster might work fine without setting resource requests, and limits, Magalix AI won't be able to generate any scalability decisions. In that case, the app dashboard will show the message shown below to alert you to take the necessary action.

Define requests and limits warning

Define requests and limits warning

Requests & limits

Kubernetes uses the requests & limits apparatuses to control resources such as CPU and memory. Requests are what the container is guaranteed to get. For example, If a container requests a resource, Kubernetes will only schedule it on a node that can give it that resource. Limits, on the other hand, is the resource threshold a container never exceed. The container is only allowed to go up to the limit, and then it is restricted.

To control what requests and limits a container can have, you can set quotas at the Container level and at the Namespace level. If you want to learn more about resources & limits see this reference from the Kubernetes documentation.

Define CPU requests & limits

To specify a CPU request for a Container, include the resources:requests field in the Container’s resource manifest. Similarly, to specify a CPU limit, include resources:limits. The Container has a CPU request of 0.5 CPU and a CPU limit of 1 CPU. If you want to learn more about CPU requests & limits see this reference from the Kubernetes documentation.

apiVersion: v1
kind: Pod
metadata:
  name: cpu-demo
  namespace: cpu-example
spec:
  containers:
  - name: cpu-demo-ctr
    image: vish/stress
    resources:
      limits:
        cpu: "1"
      requests:
        cpu: "0.5"
    args:
    - -cpus
    - "2"

Define memory requests & limits

To specify a memory request for a Container, include the resources requests field in the Container’s resource manifest. To specify a memory limit, include resources:limits. The Container has a memory request of 100 MiB and a memory limit of 200 MiB. If you want to learn more about Memory requests & limits see this reference from the Kubernetes documentation.

apiVersion: v1
kind: Pod
metadata:
  name: memory-demo
  namespace: mem-example
spec:
  containers:
  - name: memory-demo-ctr
    image: polinux/stress
    resources:
      limits:
        memory: "200Mi"
      requests:
        memory: "100Mi"
    command: ["stress"]
    args: ["--vm", "1", "--vm-bytes", "150M", "--vm-hang", "1"]