Container resources not taken into account by Kubernetes

5/26/2020

I'm trying to set the cpu consumption of my container from inside a deployment.
Unfortunatly it seems that kube is not taking it into account...

resources:
  requests:
    cpu: "0.2"

When describing the deployment it should display the requests:

$ kubectl describe deployment redis
...
  Containers:
   redis:
    Image:        redis:alpine
    Port:         6379/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:
      /redis-master-data from data (rw)
  Volumes:
...

Where is the request I set ???

The complete deployment so you can test at home ;-)

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: redis
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: redis
    spec:
      nodeName: master
      containers:
      - image: redis:alpine
        name: redis
        ports:
        - containerPort: 6379
        volumeMounts:
        - mountPath: /redis-master-data
          name: data
        resources:               # <======= Here
          requests:
            cpu: "0.2"
        resources: {}
      volumes:
      - name: data
        emptyDir: {}
status: {}

FYI : It's just a test pod and has nothing to do with redis in particular.
Thx

-- Doctor
kubernetes
resources

1 Answer

5/26/2020

Your config is wrong. You have two resources

        resources:               # <======= Here
          requests:
            cpu: "0.2"
        resources: {}

Remove resources: {} and run kubectl describe deployment redis

Pod Template:
  Labels:  app=redis
  Containers:
   redis:
    Image:      redis:alpine
    Port:       6379/TCP
    Host Port:  0/TCP
    Requests:
      cpu:        200m
    Environment:  <none>
-- RammusXu
Source: StackOverflow