Okteto Manifest Reference
okteto.yaml is a manifest format for describing development environments.
The Okteto Manifest has four main sections: build, deploy, test and dev, to define how to build, deploy, test, and develop your development environment.
The open-source version of Okteto supports features within the dev section of the Okteto Manifest. For a complete comparison of features, refer to the open-source README.
Example
build:
api:
context: api
frontend:
context: frontend
deploy:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
dev:
api:
command: ["bash"]
forward:
- 8080:8080
- 9229:9229
sync:
- api:/usr/src/app
frontend:
command: yarn start
sync:
- frontend:/usr/src/app
test:
unit:
image: okteto/golang:1
commands:
- "go test ."
Validating and Autocompleting the Okteto Manifest in your IDE
Okteto provides a JSON Schema for the Okteto Manifest to enhance your development experience by enabling autocompletion, real-time validation, and improved error detection within your IDE.
To configure this in Visual Studio Code, install the YAML extension and add the following to your workspace or user settings.json:
{
"yaml.schemas": {
"https://raw.githubusercontent.com/okteto/okteto/master/schema.json": [
"okteto.yml",
"okteto.yaml",
]
}
}
For JetBrains IDEs, you can use the built-in JSON Schema feature specifying the following params:
- Schema URL as
https://raw.githubusercontent.com/okteto/okteto/master/schema.json - Schema version as
2020.12 - Files:
okteto.ymlandokteto.yaml
Schema reference
build (object, optional)
A list of images to build as part of your development environment.
build:
base:
context: .
api:
context: api
frontend:
context: frontend
dockerfile: Dockerfile
target: dev
depends_on: base
args:
SOURCE_IMAGE: ${OKTETO_BUILD_BASE_IMAGE}
secrets:
npmrc: .npmrc
Each image supports the following fields:
args: add build arguments, which are environment variables accessible only during the build process. Build arguments with a value containing a$sign are resolved to the environment variable value on the machine Okteto is running on.context: the build context. Relative paths are relative to the location of the Okteto Manifest (default:.)depends_on: list of images that need to be built first.dockerfile: the path to the Dockerfile. It's a relative path to the build context (default:Dockerfile)image: the name of the image to build and push. In clusters that have Okteto installed, this is optional (if not specified, the Okteto Registry is used).secrets: list of secrets exposed to the build. The value of each secret refers to a file. Okteto will resolve references containing a$sign in this file to environment variables on the machine Okteto is running on.target: build the specified stage as defined inside the Dockerfile. See the multi-stage official docs for details.
You can build all these images by running okteto build, or okteto build xxx to build a single one.
Follow this document for a list of environment variables available in your deploy commands to refer to the images built in the build section of your Okteto Manifest.
Okteto will automatically add all the build environment variables from all previous images in the dependency chain as build arguments. To refer to them, remember to add the
ARGinstruction on your Dockerfile.
dependencies ([string], optional)
A list of repositories you want to deploy as part of your development environment.
dependencies:
- https://github.com/okteto/movies-frontend
Use okteto deploy --dependencies to force the redeployment of your dependencies.
There is also an extended notation to configure how to deploy your dependencies:
dependencies:
frontend:
repository: https://github.com/okteto/movies-frontend
manifest: okteto.yaml
branch: main
variables:
ENVIRONMENT: development
DEBUG: true
wait: true
timeout: 15m
When specifying the manifest path, the dependency deployment will use this path as the location of the Okteto Manifest in the Git repository.
deploy ([string], optional)
A list of commands to deploy your development environment.
It's usually a combination of helm, kubectl, and okteto commands.
Deploy with Commands
For example, deploy a Helm chart using a command to invoke the helm CLI:
deploy:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
You can name your commands with the following syntax:
deploy:
- name: Deploy Movies App with Helm
command: helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
You can share environment variables between steps by adding them to $OKTETO_ENV:
deploy:
- name: Set env value
command: echo "OKTETO_FOLDER=/app" >> $OKTETO_ENV
- name: Get env value
command: echo "$OKTETO_FOLDER" # Prints /app
Follow this document for a list of environment variables available in your deploy commands.
Deploy remotely (recommended)
If you define an image in your deploy section, okteto deploy will run in remote mode:
deploy:
image: okteto/pipeline-runner:1.0.0
context: .
commands:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
The context field specifies the working directory for running the deploy commands. If left empty, it defaults to the directory containing the Okteto Manifest.
If you don't define an image, you can run in remote mode adding the remote field to your manifest:
deploy:
remote: true
commands:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
Follow our docs to know more about remote execution and how it works.
Deploy with Compose
Deploy a Docker Compose file using the following notation:
deploy:
compose: docker-compose.yml
Images specified in the build section of the Okteto Manifest overrides the image associated with services sharing the same name in your Docker Compose files.
There is an extended notation to deploy several Docker Compose files and endpoints:
deploy:
compose:
- file: docker-compose.yml
services:
- frontend
- file: docker-compose.dev.yml
services:
- api
endpoints:
- path: /
service: frontend
port: 80
- path: /api
service: api
port: 8080
The services field allows us to deploy only a subset of the services in the Docker compose file (default to all services).
Only the volumes and endpoints of the services specified in the services field are deployed.
You can combine deploy commands with Docker Compose files:
deploy:
commands:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
compose: docker-compose.yml
Your deploy commands will be executed before deploying your Docker Compose files.
Divert
Divert is useful when you have many services and you only want to deploy a subset of them in your development environment, while connecting these services with a shared environment that runs all your microservices.
When divert is enabled, Okteto adds the header baggage.okteto-divert to every request coming from the developer namespace.
If the request reaches the shared namespace and matches a diverted virtual service, Okteto redirects the request back to the developer namespace.
To divert a virtual service as part of your development environment, use the following notation:
deploy:
commands:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
divert:
driver: istio
virtualServices:
- name: vs1
namespace: staging
routes:
- route1
- route2
hosts:
- virtualService: frontend
namespace: staging
driver: the backend for divert. Currently, the only supported driver isistio.virtualServices: a list of virtual services to divert. Each virtual service is defined with it's name, namespace, and an optional list of routes to be diverted. By default, all routes are diverted.hosts: the list of hosts you want to divert in the developer namespace. Requests to these virtual services will have the headerbaggage.okteto-divertinjected.
destroy ([string], optional)
A list of commands to destroy external resources created by your development environment.
okteto destroy automatically takes care of destroying all the Kubernetes resources created by okteto deploy.
Use the destroy section if you create resources out of the scope of Kubernetes, like s3 buckets or RDS databases.
destroy:
- helm uninstall movies
Follow this document for a list of variables available in your destroy commands.
Destroy remotely (recommended)
If you define an image in your destroy section, okteto destroy will run in remote mode:
destroy:
image: okteto/tfenv-ci:1.4
context: .
commands:
- terraform destroy --auto-approve
The context field specifies the working directory for running the destroy commands. If left empty, it defaults to the directory containing the Okteto Manifest.
If you don't define an image, you can run in remote mode adding the remote field to your manifest:
destroy:
remote: true
commands:
- helm uninstall movies
Follow our docs to know more about remote execution and how it works.
dev (object, optional)
A list of development containers to define the behavior of okteto up and synchronize your code in your development environment.
dev:
api:
command: ["bash"]
forward:
- 8080:8080
- 9229:9229
sync:
- api:/usr/src/app
frontend:
command: yarn start
sync:
- frontend:/usr/src/app
The name of each development container must match the name of the Kubernetes Deployment or Statefulset that you want to put on development mode.
If the name of your Deployment or Statefulset is dynamically generated, use the selector field to match the Deployment or Statefulset by labels.
Each development container supports the following fields:
affinity (Affinity, optional)
Affinity allows you to constrain which nodes your development container is eligible to be scheduled on, based on labels on the node. More information about Kubernetes affinities is available here.
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: role
operator: In
values:
- web-server
topologyKey: kubernetes.io/hostname
autocreate (bool, optional)
If set to true, okteto up creates a deployment if name doesn't match any existing deployment in the current namespace (default: false).
command (string, optional)
Sets the command of your development container. If empty, it defaults to sh:
command: bundle exec thin -p 3000
The command can also be a list:
command: ["bundle", "exec", "thin", "-p", "3000"]
container (string, optional)
The name of the container in your deployment you want to put on development mode. By default, it takes the first one.
environment ([string], optional)
Add environment variables to your development container. If a variable already exists on your deployment, it will be overridden with the value specified on the manifest.
Environment variables with only a key, or with a value with a $ sign resolve to their values on the machine Okteto is running on, which can be helpful for secret or machine-specific values.
environment:
environment: development
name: user-${USER:peter} ## will be replaced by the value of $USER or by "peter" if the variable USER does not exist
DBPASSWORD: ## will be given the value of $DBPASSWORD if it exists
They can also be defined as a list, for example:
environment:
- environment=development
- name=user-${USER:peter} ## will be replaced by the value of $USER or by "peter" if the variable USER does not exist
- DBPASSWORD
envFiles
Add environment variables to your development container from a file.
envFiles:
- .env1
- .env2
Environment variables declared in the environment section override these values.
externalVolumes ([string], optional)
A list of persistent volume claims (not managed by Okteto) that you want to mount in your development container. This is useful to share cache information between different development containers. For example, to share the go cache between different development containers, you could define:
externalVolumes:
- go-cache:/root/.cache/go-build/
on different Okteto Manifests. You can also mount a relative subpath of a given persistent volume claim:
externalVolumes:
- pvc-name:subpath:/var/lib/mysql
forward ([string], optional)
A list of ports to forward from your development container.
The list should follow the localPort:remotePort notation and each element should be unique.
You can also access other services running in your namespace by using the notation localPort:remoteService:remotePort.
forward:
- 8080:80
- 5432:postgres:5432
You can also use the extended notation below to configure the service to be exposed using a label selector or its name.
forward:
- localPort: 8080
remotePort: 80
name: app
- localPort: 5432
remotePort: 5432
labels:
app: db
Once your development container is up and running, you will be able to access the port directly by using localhost:localPort.
Common uses of port forwarding are:
- Access a service via
localhostinstead of via an ingress- Remote debugging
- Connect to a hot reloader via a websocket
If Okteto can't forward a port (typically because they are already taken), the okteto up command will fail with an error.
initContainer (object, optional)
Allows you to override the okteto init container configuration of your development container.
initContainer:
image: okteto/bin:1.2.22
resources:
requests:
cpu: 30m
memory: 30Mi
limits:
cpu: 30m
memory: 30Mi
interface (string, optional)
Port forwards and reverse tunnels will be bound to this address. Defaults to localhost.
interface: 0.0.0.0
image (string, optional)
Sets the docker image of your development container. Defaults to the image specified in your deployment.
More information on development images here
You can use an environment variable to replace the image, or any part of it:
image: okteto/dev:$USER
More information on how to use private images for your development container is available here.
imagePullPolicy (string, optional)
The image pull policy of your development environment (default: Always)
lifecycle (boolean, optional)
Configures lifecycle hooks for your development container. Lifecycle hooks allow you to execute commands when your container starts or stops, enabling you to automate setup or cleanup tasks.
If set to true, both postStart and preStop lifecycle events are enabled when running okteto up inheriting the lifecycle from the original container (default: false).
For more information about Kubernetes lifecycle hooks, see the official Kubernetes documentation.
lifecycle: true
This enables both postStart and preStop events to use the default commands defined in your Kubernetes deployment.
For more granular control, you can enable or disable specific lifecycle events and define custom commands to run during those events.
lifecycle:
postStart:
enabled: true
command: "echo 'Container has started'"
preStop:
enabled: true
command: "echo 'Container is stopping'"
- postStart:
- enabled (boolean): Set to true to enable the postStart event (default: false).
- command (string): The command to execute when the container starts.
- preStop:
- enabled (boolean): Set to true to enable the preStop event (default: false).
- command (string): The command to execute just before the container stops.
metadata (object, optional)
The metadata field allows to inject labels and annotations into your development container.
metadata:
annotations:
fluxcd.io/ignore: "true"
labels:
custom.label/dev: "true"
mode (string, optional)
The development mode used for a development environment. There are two options available for this field:
sync: the standard and default mode. This mode will synchronize your code with the remote development containerhybrid: use this mode if you want to run your service locally but run the rest of your application components in the cluster
More information about development modes is available here.
nodeSelector (map[string]string, optional)
List of labels that the node must have to include the development container on it. More information about Kubernetes node selectors is available here.
nodeSelector:
disktype: ssd