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.yml
andokteto.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.
If you use multiple Dockerfiles, you can use different ignore-files for each Dockerfile. You do so using a special naming convention for the ignore-files. Place your ignore-file in the same directory as the Dockerfile, and prefix the ignore-file with the name of the Dockerfile, as shown in the following example. e.g. dev.Dockerfile
and dev.Dockerfile.dockerignore
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
ARG
instruction on your Dockerfile.
dependencies ([string], optional)
A list of repositories you want to deploy as part of your development environment.
Dev environments with declared dependencies will surface additional options during redeploy and destroy actions in the Okteto UI
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.
If you want to deploy only a subset of the services in the Docker compose file, you can use the services
field. By default, all services are deployed.
deploy:
compose:
file: docker-compose.yml
services:
- frontend
There is an extended notation to deploy several Docker Compose files and endpoints. Only the volumes
and endpoints
of the services specified in the services
field are deployed:
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
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 allows you to create lightweight development environments that include only the services you are actively working on while leveraging an existing shared environment for all other microservices. This approach significantly reduces infrastructure costs and complexity, especially in large microservices environments.
Okteto supports two different drivers: nginx
(default) and istio
.
- Nginx
- Istio
Use the nginx
driver if your applications rely on Okteto-generated endpoints for service-to-service communication.
To deploy a diverted
development environment, add the divert.namespace
key under the deploy
section of your Okteto Manifest.
This configuration tells Okteto where to redirect requests for services not deployed in your current development environment.
deploy:
commands:
- helm upgrade --install movies chart --set api.image=${OKTETO_BUILD_API_IMAGE} --set frontend.image=${OKTETO_BUILD_FRONTEND_IMAGE}
divert:
driver: nginx
namespace: staging
driver
: Specifies the backend to divert requests. Usenginx
(or leave this field unspecified) to use the default Nginx driver.namespace
: The namespace that holds the full shareable environment. When a request is directed to a service that wasn't created by thedeploy
command, Okteto will automatically direct it to the environment running on this namespace.
When divert
is enabled, Okteto injects the key okteto-divert
within the header baggage
into every request that passes through your development ingress. This header allows Okteto to route the request intelligently between services running in your personal namespace and services running in a shared environment.
To maintain request routing across service boundaries, we recommend propagating the baggage
(with the key okteto-divert
) header to all downstream service calls.
Beyond request routing, this header can also be used to:
- Route messages to different queues or topics
- Redirect requests to services in other namespaces
- Dynamically select the correct database instance for read/write operations
Check out this GitHub repository for practical examples of how to integrate Divert into your service communication flows.
Use the istio
driver if your development environments use Istio for managing service-to-service communication.
When divert is enabled, Okteto injects the the key okteto-divert
within the header baggage
to every request coming from the developer Namespace.
If a request reaches the shared Namespace and matches a diverted virtual service, Okteto automatically 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
: Specifies the backend to divert requests. Useistio
to use the Istio driver.virtualServices
: A list of virtual services to divert. Each virtual service is defined by 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 keyokteto-divert
as part of thebaggage
header injected.
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
in your namespace.
Use the destroy
section if you create resources outside of your namespace, like clusterroles, or 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
localhost
instead 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