Sobes.tech
Intern

How to limit resources of containers in Kubernetes?

sobes.tech AI

Answer from AI

In Kubernetes, container resources are limited using the resources.requests and resources.limits fields in the Pod or Deployment manifest.

  • requests are the minimum resources guaranteed to be allocated to the container.
  • limits are the maximum resources the container cannot exceed.

Example of CPU and memory limits:

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    resources:
      requests:
        memory: "128Mi"
        cpu: "250m"
      limits:
        memory: "256Mi"
        cpu: "500m"

This approach helps manage load and prevent a single container from consuming excessive resources.