Contents

Kubernetes Resource Requirements and Limits

Default Resource Unit

CPUMEMDISK
0.5256Mi

Default Resource Limit

CPUMEMDISK
1512Mi

Lower Limit

CPUMEMDISK
1m256Mi

1 CPU as in Cloud Services

ServiceUnit
AWS1 AWS vCPU
Google1 GCP Core
Azure1 Azure Core / 1 Hyperthread

G vs Gi / M vs Mi / K vs Ki

UnitDescriptionValue
1 GGigabyte1,000,000,000 bytes
1 GiGibibyte1,073,741,824 bytes
1 MMegabyte1,000,000 bytes
1 MiMebibyte1,048,576 bytes
1 KKilobyte1,000 bytes
1 KiKibibyte1,024 bytes

PODSpec

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: my-app
spec:
  containers:
    - name: nginx-container
      image: nginx
      ports:
        - containerPort: 8080
      resources:
        requests:
          memory: "1Gi"
          cpu: 1
        limits:
          memory: "2Gi"
          cpu: 2

Exceed Limits

UnitAction
CPUThe POD cannot use more CPU over the limit.
MEMThe POD can use more memory over the limit, but it’s terminated when the usage is over the Physical limit.

The resources are not enough in the cluster

The PODs are in the Pending status.

Configure the Default Resource Unit of Container

configure memory default resource of container

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: LimitRange
metadata:
  name: mem-limit-range
spec:
  limits:
    - default:
        memory: 512Mi
      defaultRequest:
        memory: 256Mi
      type: Container

configure cpu default resource of container

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: LimitRange
metadata:
  name: cpu-limit-range
spec:
  limits:
    - default:
        cpu: 1
      defaultRequest:
        cpu: 0.5
      type: Container

References