k8s define resources withouts requests

4/11/2021

I want to define my service only with resource limits, so instead:

resources:
  requests:
    memory: "512Mi"
    cpu: "500m"
  limits:
    memory: "1024Mi"
    cpu: "1000m"

I will use only:

resources:
  limits:
    memory: "1024Mi"
    cpu: "1000m"

Will that be possible, or I must also define requests?

Thanks.

-- jrz
kubernetes

1 Answer

4/11/2021

It is totally possible. A pod definition below will work as well:

apiVersion: v1
kind: Pod
metadata:
  name: resource-limits
spec:
  containers:
  - name: resource-limits
    image: nginx
    resources:
      limits:
        memory: "512Mi"
        cpu: "500m"

If a Container specifies its own memory limit, but does not specify a memory request, Kubernetes automatically assigns a memory request that matches the limit. Similarly, if a Container specifies its own CPU limit, but does not specify a CPU request, Kubernetes automatically assigns a CPU request that matches the limit.

So if you do kubectl describe po, you see this:

Containers:
  resource-limits:
    Container ID:   docker://a934c0e2d503a9ebc164aedf40ebecf3263f5bf5a03c196650a6e0d67d83c16c
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:6b5f5eec0ac03442f3b186d552ce895dce2a54be6cb834358040404a242fd476
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 11 Apr 2021 15:51:20 +0100
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     500m
      memory:  512Mi
    Requests:
      cpu:        500m
      memory:     512Mi
-- rock&#39;n rolla
Source: StackOverflow