Endpoints for Docker Compose
Okteto creates HTTPS endpoints for the applications you deploy with Docker Compose. There are two ways to define them: public ports and the endpoints section.
Public Ports
The ports of a service are only accessible from the private network of the cluster by default:
services:
api:
build: api
ports:
- 8080
To make a port public, use the HOST:CONTAINER notation. Okteto creates an endpoint for it:
services:
api:
build: api
ports:
- 8080:8080
The hostname of the endpoint is <service>-<namespace>.<okteto-subdomain>, for example api-<namespace>.<okteto-subdomain>. If a service has more than one public port, Okteto creates one endpoint per port, with the hostname <service>-<port>-<namespace>.<okteto-subdomain>.
Okteto never makes public the default ports of databases and debuggers, such as 5432 for PostgreSQL or 6379 for Redis, even with the HOST:CONTAINER notation. The Docker Compose reference lists every port. To expose one of these ports, use the endpoints section.
The endpoints Section
Use the endpoints section to route several paths to different services under one hostname:
services:
frontend:
build: frontend
api:
build: api
endpoints:
- path: /
service: frontend
port: 80
- path: /api
service: api
port: 8080
The hostname is <name>-<namespace>.<okteto-subdomain>, where <name> is the name of your Development Environment.
To create several endpoints, use a map with the name of each endpoint:
endpoints:
landing:
- path: /
service: nginx
port: 80
web:
- path: /
service: frontend
port: 80
- path: /api
service: api
port: 8080
This example creates the hostnames landing-<namespace>.<okteto-subdomain> and web-<namespace>.<okteto-subdomain>.
To add labels or annotations to an endpoint, use the extended notation with rules. For example, to apply a Custom Endpoints annotation:
endpoints:
annotations:
dev.okteto.com/hide-from-ui: "true"
rules:
- path: /
service: frontend
port: 3000
- path: /api
service: api
port: 8080
Ingress or HTTPRoute
Okteto creates an Ingress or an HTTPRoute for each endpoint. You don't need to change your Docker Compose file: the variable OKTETO_DEFAULT_GATEWAY_TYPE selects the type, with the value ingress or gateway. You can set it as:
- An Okteto Variable, which applies to your deployments.
- An Admin Variable, which changes the default for every user of your Okteto instance.
An Okteto Variable takes precedence over an Admin Variable. If neither is set, Okteto uses the Helm value unsupported.defaultGateway.type of your Okteto instance, which defaults to ingress.