Traefik with PostgreSQL

Hi,

I have issues deploying PostgreSQL data base with traefik

This is my conf

version: "3.3"

services:
  traefik:
    image: "traefik:v3.2"
    container_name: "traefik"
    command:
      #- "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
      - "--entryPoints.db.address=:5432" 
    ports:
      - "80:80"
      - "8080:8080"
      #- "5432:5432"
    volumes:
      - "/run/podman/podman.sock:/var/run/docker.sock:ro"
    networks:
      - traefik_net  # Esto es correcto. Aquí se conecta a la red externa.

networks:
  traefik_net:
    external: true  # La red externa debe ser definida aquí, fuera de los servicios.

version: '3.9'

services:
  postgres:
    image: postgres:14-alpine
    container_name: postgres
    restart: unless-stopped
    ports:
      - 5432:5432  # Exponer el puerto 5432 para acceso local
    volumes:
      - ./postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_DB=${POSTGRES_DB}
    labels:
      - "traefik.enable=true"  # Habilitar el servicio para Traefik
      - "traefik.tcp.routers.postgres.rule= HostSNI(`db.sky.co`)"  # Host TCP para PostgreSQL
      - "traefik.tcp.routers.postgres.entrypoints=db"  # EntryPoint TCP configurado en Traefik
      - "traefik.tcp.services.postgres.loadbalancer.server.port=5432"  # Puerto 5432 de PostgreSQL dentro del contenedor
    networks:
      - traefik_net

networks:
  traefik_net:
    external: true

Have error in hostSNI entry db service posgres

ERRORS

invalid rule: " HostSNI(db.smy.co)" , has HostSNI matcher, but no TLS on router

Let me know how can solve.

Place 3 backticks before and after code/config to make it more readable and preserve spacing, which is important in yaml.

Hi, my apologies was fixed.

When using HostSNI you need to enable TLS.

Without TLS you can only use HostSNI(`*`), so a single target service on the entrypoint.

Thanks for quick replay, but I want to know if I’m in right way?

Is the best way use for connection to database ( use udp) or you recommend other way to config?

Thanks

I have worked with a few databases (Oracle, MySQL, Postgres, MSSQL, MongoDB), but non used UDP, all used TCP. But that’s not really a Traefik related question.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.