How to configure K8S resources (limits/requests) from docker-compose.yml

I’m using docker-compose.yml to deploy to Okteto. I’ve noticed that the .spec.containers[].resources values for limits and requests are set, but have default values. I’d like to do some tuning and am wondering how best to do that in my docker-compose.yml file.

Okteto docs mention setting the resources under the service object:

However, when I tried that I got an error saying that the resources was not expected:

$ docker-compose up
services.my-service Additional property resources is not allowed

I see in the docker-compose docs: Compose file deploy reference | Docker Documentation

it looks like I need a deploy section under my service. Is that the right way to do it with Okteto?

Hey @brett! Could you post your docker-compose file? (make sure to remove any private data)

Sure thing. This was my first attempt, and the one that generated the error about the extra property:

services:
  my-service:
    build:
      context: .
      args:
      . . .(truncated)
    environment:
      . . .(truncated)
    volumes:
      - .:/app
    resources:
      requests:
        cpu: 300m
        memory: 500Mi
      limits:
        cpu: 500m
        memory: 800Mi

Next up I tried modifying my docker-compose to conform to what I saw in the Docker documentation:

services:
  my-service:
    build:
      context: .
      args:
      . . .(truncated)
    environment:
      . . .(truncated)
    volumes:
      - .:/app    
    deploy:
      resources:
        reservations:
          cpus: '0.25'
          memory: 400M
        limits:
          cpus: '0.5'
          memory: 800M

This :point_up: works fine locally, and I can also deploy it to Okteto with okteto deploy. I noticed that the deploy.resources.limits section is copied into the corresponding deploy spec in K8S, so that’s part of what I need :smile_cat:

The deploy.resources.reservations section was not copied into the K8s “requests” though. I’m still not sure how to configure that.

@brett reservations are not “making it” to the kubernetes object; this is a bug in the okteto CLI. We filed K8S resources.requests.memory from docker-composeis not beeing set · Issue #3383 · okteto/okteto · GitHub to track this.

1 Like