Home Putting resource limits on your Kubernetes Pods
Post
Cancel

Putting resource limits on your Kubernetes Pods

CPU and memory resource memory limits can be applied to pods in deployments (and on namespaces). Doesn’t look like a rock-hard limit; exceeding the limits may be allowed for short-term cases.

…the container’s CPU use is being throttled, because the container is attempting to use more CPU resources than its limit.

…a Container is not allowed to use more than its memory limit. If a Container allocates more memory than its limit, the Container becomes a candidate for termination.

Sources:
https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/ https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/

No limits:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

Limits:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: 100m
            memory: 200Mi
  • CPU limits in this case are set to 100 milli-cpus or 10% of one CPU before this pod is throttled. 1000m would be equal to 1 CPU.
  • CPU limits will never dedicate a CPU solely to one pod.
  • The memory limited listed here is 200MiB.

You can see the limits in place by running this command:

1
2
3
4
$ kubectl describe deploy nginx | grep -A2 "Limits:"
    Limits:
      cpu:        100m
      memory:     200Mi

QOS settings for each pod can be set. I have not investigated these yet.
https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/

This post is licensed under CC BY 4.0 by the author.