Running postgress with okteto cli not working

Hello:

Is there a reason I am not able to run a database with the okteto cli? Below is my okteto manifest file for a postgres database. Whenever I run this, I get an error with the command. I have tried different notations for the command but it still does not work. I am able to run and connect to a postgress database when I run it locally on my machine with docker-compose. The docker-compose file does not have a command, yet it still works.

Am I missing something obvious here?

Okteto.yml file (does not work)

  postgresql:
      name: postgresql
      image: postgres:14.12-bullseye
      autocreate: true
      command: ["sh","-c","postgres -c log_statement=all"]
      volumes:
        - /root/.vscode-server
      securityContext:
        runAsUser: 1000
        capabilities:
          add:
          - SYS_PTRACE
      forward:
        - 5434:5432
      persistentVolume:
        enabled: true
      environment:
        SSH_AUTH_SOCK: /ssh-agent
        POSTGRES_PASSWORD: example
        POSTGRES_USER: example

docker-compose.yml file (works from my machine)

version: '3.9'

services:
  db:
    image: postgres:14.12-bullseye
    restart: always
    ports:
      - 5432:5432
    shm_size: 128mb
    environment:
      POSTGRES_USERNAME: example
      POSTGRES_USER: example
      POSTGRES_PASSWORD: example

Thanks,

Julio

Hey Julio,

The dev section of the okteto.yaml manifest is meant to be used to define the overrides you want okteto to apply to the services you are developing when you run okteto up, and to tell okteto where to synchronize your code. It is not designed to deploy databases or other similar types of services.

When using the open source CLI, this is the workflow that we recommend for the kind of usage you describe:

  1. Deploy your existing application (services + databases) using your regular Kubernetes tooling (helm, kubectl, etc…)
  2. Run “okteto up” on one of the microservices that call the database
  3. Develop remotely in kubernetes

In this scenario, your okteto.yaml should only contain information about the microservices you are developing (e.g. your API). This sample follows that pattern, in case it helps.


When using the paid version of Okteto, you can use the deploy section of the manifest to tell okteto how to deploy your entire application when running okteto deploy or okteto up commands. You can even use docker-compose files. This sample follows that model..

Thank you Ramiro,

This makes sense. I was indeed able to deploy the database using a helm chart for our specific needs. I am really interested in the docker-compose option for this purpose, so hopefully we can try this out in the near future.

Julio

1 Like