Service YAML reference

A service is a set of containers running the same container image.

Below is an example of a service.yml:

1
2
3
4
5
6
7
8
9
10
name: test
replicas: 3
containers:
nginx:
image: nginx:alpine
environment:
- NAME=VALUE
ports:
- 80
command: start.sh

Each key is documented below:

name (required)

The name of the service. Every service on the same project will be able to ping this service using its name.

1
name: api

Service names should be unique per project.

Service names only accept alphanumeric characters and dashes.

replicas (optional)

The number of instances running this service (default: 1).

1
replicas: 3

volumes (optional)

It is the set of volumes for this service.

Each volume might have the following keys:

Persistent (optional)

Indicates if the volume must be created persistent (default: false).

1
persistent: true

Size (optional)

Indicates the size of the volume (default: 20Gi).

1
size: 40Gi

containers (required)

It is the set of containers running this service.

The most common case is to have a single container, but there are other use cases where more than a single container is needed (what it is also known as Pods).

Each container might have the following keys:

image (required)

The image used to deploy this container. This is the only mandatory key.

1
2
3
image: drupal
image: nginx:alpine
image: my.registry.com/redis

environment (optional)

A list of environment variables to add in the container at launch. They are represented using an array format.

1
2
3
environment:
- USER=user1
- PASSWORD=password1

If your project has any secrets declared, you can use them instead of the value, and okteto will replace it during deployment time:

1
2
3
environment:
- USER=user1
- PASSWORD=$DB_PASSWORD

command (optional)

Overrides the default command in the container image.

1
command: echo 'Hello Okteto!'

args (optional)

Overrides the default args in the container image.

1
2
3
args:
- -f
- filename

working_dir (optional)

Overrides the default working dir in the container image.

1
working_dir: /root

ports (optional)

Defines the public ports that are accessible from the internet. If the project has configured an ingress controller, ports are exposed using ingress rules. If not, a load balancer is created.

1
2
ports:
- 80

expose (optional)

Defines the private ports that are accessible from inside the cluster.

1
2
expose:
- 80

ingress (optional)

Defines the ingress rules to access this container (only available in projects configured with an ingress controller).

1
2
3
4
ingress:
- Host: api
Path: /api/v1
Port: 8000

This would create an ingress rule for the host api and the path /api/v1 to redirect to port 8000 in this container.

resources (optional)

Specifies the resources that a container can consume. It maps the same behaviour than kubernetes resources. For more information, go to the kubernetes documentation.

1
2
3
4
5
6
7
resources:
limits:
memory: "128Mi"
cpu: "500m"
requests:
memory: "64Mi"
cpu: "250m"

dev (optional)

Specifies the runtime for activating the dev mode in this container.

1
2
3
4
5
6
dev:
image: node:8
command: node
args:
- -d
path: /usr/share/nginx/html

image (optional)

It is the docker image to use (the default is the same defined for the container).

1
image: node:8

command (optional)

Redefine the command of the dev container image.

1
command: node

args (optional)

Redefine the command arguments of the dev container image.

1
2
args:
- -d

path (optional)

Indicates where to synchronize your local source code into the dev container (default: /src).

1
path: /usr/share/nginx/html

More information: