Okteto CLI
The Okteto Command Line Interface is a unified tool to manage your development environments.
Synopsis
$ okteto [options] <command> <subcommand> [parameters]
Use okteto command --help
for information on a specific command. The synopsis for each command shows its parameters and their usage. Optional parameters are shown in square brackets.
Options | Values |
---|---|
--loglevel | debug, info, warn, error |
The amount of information outputted (defaults to warn).
Advanced configuration
It is possible to handle timeouts from the client side when communicating with the buldkit daemon through the Okteto CLI. To do so, the following environment variables can be modified:
OKTETO_KEEPALIVE_CLIENT_TIME_MS
: After this duration of time, if the client doesn't see any activity it will ping the server to see if the transport is still alive. If set below 10s, a minimum value of 10s will be used. The current default value is infinity.OKTETO_KEEPALIVE_CLIENT_TIMEOUT_MS
: After sending a keepalive ping, the client waits for this duration of time and if no activity is seen even after that the connection is closed. The current default value is 20 seconds.OKTETO_KEEPALIVE_CLIENT_PERMIT_WITHOUT_STREAM
: If true, the client sends keepalive pings even with no active RPCs. If false, when there are no active RPCs, Time and Timeout will be ignored and no keepalive pings will be sent. False by default.
Available commands
analytics
Enable / Disable analytics collection. Analytics are enabled by default
$ okteto analytics [parameters]
Options | Description |
---|---|
--disable | Disables analytic collection |
Okteto only collects information to help us understand how our users interact with the product. We don't collect any personally identifiable information.
When you use the okteto CLI, the following information is collected:
- The name of the action
- A timestamp of when it was run
- Your version of the CLI
- Your OS
- An anonymous machine ID (we use https://github.com/denisbrodbeck/machineid for this)
- A user ID if you are currently logged in to Okteto
- An action ID (to correlate multiple actions performed during a command's execution)
Please reach out to us if you have any questions or concerns about the information collected.
build
Build and push the images defined in the build
section of your okteto manifest:
$ okteto build [service...]
If your okteto context points to an Okteto URL, images are built using the Okteto Build Service.
Otherwise, images are built using your local Docker daemon. If you want to use another BuildKit instance, set the variable BUILDKIT_HOST
to point to its address, using the format HOST:PORT
.
The following flags can be used (very similar to docker build
):
Options | Type | Description |
---|---|---|
--file | (string) | The path to the okteto manifest |
--no-cache | (bool) | Do not use cache when building the image (default: false ) |
--secret | (list) | Secret files exposed to the build. Format: id=mysecret,src=/local/secret |
--export-cache | (string) | Image tag for exported cache when build (optional) |
--cache-from | (list) | List of cache source images (optional) |
--platform | (string) | Specify which platform to build the container image for (optional) |
You can also use the
-f
to point to a Dockerfile. In this mode,okteto build
will ignore your Okteto manifest, and directly build the image defined in the Dockerfile. Use this to build images that are not defined on your Okteto manifest.
With okteto build --platform
you can specify the platform (or architecture) for which you'd like to build the container images. For example, you could use a multiplatform image and the okteto build --platform
command to deploy your web application on a Kubernetes cluster that consists of nodes running on both x86-64 and ARMv7 architectures.
By using the multiplatform images built using this method, you can deploy the same images across the cluster without worrying about the underlying hardware differences.
Let's consider an example where you have a Node.js application that you want to build and deploy on both x86_64 and ARM-based platforms. You have a Dockerfile in your project directory that defines the build process. Here's how Okteto CLI can help you build multiplatform images for your application:
- Building the image for x86_64 architecture:
okteto build -t myapp:latest --platform linux/amd64
- Building the image for ARMv7 architecture:
okteto build -t myapp:latest --platform linux/arm/v7
- Building a multiarchitectural image:
okteto build -t myapp:latest --platform linux/amd64,linux/arm/v7
This command builds a multi-architecture Docker image named myapp with the latest tag for both x86_64 and ARM platforms.
By using these commands, you can easily build the application image for different platforms without needing to maintain separate Dockerfiles or perform manual modifications. This is particularly useful when you want to deploy your application to heterogeneous environments where you have both x86_64 and ARM-based devices, such as a mixed-cluster Kubernetes setup.
context
Set the default context.
A context is a group of cluster access parameters. Each context contains a Kubernetes cluster, a user, and a namespace. The current context is the default cluster/namespace for any Okteto CLI command.
$ okteto context
This will prompt you to select one of your existing contexts or to create a new one:
A context defines the default cluster/namespace for any Okteto CLI command.
Select the context you want to use:
Use the arrow keys to navigate: ↓ ↑ → ←
▸ https://okteto.example.com *
minikube
Create new context
Options | Type | Description |
---|---|---|
--token | (string) | API token for authentication. Use this when scripting or if you don't want to use browser-based authentication. |
--namespace | (string) | Namespace of your okteto context. |
--builder | (string) | URL of the builder service |
When you run okteto context
, an account will be created for your own URL
if it's the first time you set the context in.
The CLI will exchange an authorization token with URL
and save your API token and Okteto certificates information under $HOME/.okteto/
.
Using Environment Variables to authenticate
Environment variables provide another way to specify your credentials. This is the recommended method when scripting tasks or when creating preview environments.
The supported environment variables are:
OKTETO_TOKEN
: Specifies the personal access token to useOKTETO_URL
: Specifies the Okteto URL. If missing, it defaults to https://okteto.example.com
Available subcommands:
delete
Delete one or more contexts.
For example, to delete the Okteto context, run:
$ okteto context delete https://okteto.example.com https://okteto2.example.com
list
List available contexts.
$ okteto context list
Name Namespace Builder Registry
https://okteto.example.com * cindy tcp://buildkit.okteto.example.com:1234 registry.okteto.example.com
minikube default docker -
show
Print the current context.
$ okteto context show
Options | Type | Description |
---|---|---|
--include-token | (bool) | Include the token in the output (default: false ) |
--output | (string) | Output format. One of: json , yaml (default: json ) |
{
"name": "https://okteto.example.com",
"token": "REDACTED", # only printed using flag: --include-token
"namespace": "cindy",
"builder": "tcp://buildkit.okteto.example.com:1234",
"registry": "registry.okteto.example.com",
"isOkteto": true
}
use
Set the default context.
$ okteto context use
This will prompt you to select one of your existing contexts or to create a new one.
You can also specify an Okteto URL:
$ okteto context use https://okteto.example.com
✓ Using context cindy @ okteto.example.com
Or a Kubernetes context:
$ okteto context use minikube
✓ Using context default @ minikube
deploy
Deploy your development environment by running the commands specified in the deploy
section of your okteto manifest.
If the images in the build
section don't exist, okteto deploy
automatically builds and pushes all these images.
If the repositories in the dependencies
section haven't been deployed yet, okteto deploy
deploys these dependencies automatically.
The command is executed relative to the path where the manifest is located. This means, that if the manifest is at any subfolder, the pipeline will use the context of the subfolder where the manifest is defined.
$ okteto deploy
Options
Options | Type | Description |
---|---|---|
--build | (bool) | Force build of images in the build section (defaults to false ) |
--dependencies | (bool) | Force deployment of repositories in the dependencies section (defaults to false ) |
--file | (string) | The location of the okteto manifest (defaults to okteto.yaml ) |
--name | (string) | The name of the development environment (defaults to the repo/folder name) |
--namespace | (string) | Overwrites the namespace where the development environment is deployed |
--timeout | (duration) | The duration to wait for the development environment deployment to complete. Any value should contain a corresponding time unit e.g. 1s, 2m, 3h (default 5m0s) |
--var | (list) | Set a pipeline variable (can be set more than once) |
--wait | (bool) | Wait until the pipeline finishes (defaults to false) |
--no-bash | (bool) | Execute the command using the container's default shell instead of bash (defaults to false) |
--remote | (bool) | Run the deploy commands in your Okteto cluster. Okteto will connect your local SSH agent with the cluster. For example, this lets you clone any private repository as part of your manifest execution as long as your local agent has the proper ssh key configured |
Executed commands will be executed using bash unless the
--no-bash
flag has been specified.
destroy
Destroy your development environment. It automatically destroys all the Kubernetes resources created by okteto deploy. If you need to destroy external resources (like s3 buckets or other Cloud resources), use the destroy section of the Okteto Manifest.
$ okteto destroy
Options
Options | Type | Description |
---|---|---|
--name | (string) | The name of the development environment (defaults to the folder name) |
--namespace | (string) | overwrites the namespace where the development environment is deployed |
--timeout | (string) | The duration to wait for the development environment to be destroyed. Any value should contain a corresponding time unit e.g. 1s, 2m, 3h (default 5m0s) |
--volumes | (bool) | Destroy the persistent volumes created by the development environment (defaults to false ) |
--wait | (bool) | Wait until the development environment is destroyed (defaults to false ) |
--no-bash | (bool) | Execute the command using the container's default shell instead of bash (defaults to false) |
--all | (bool) | Destroy everything (defaults to false ) |
--remote | (bool) | Run the deploy commands in your Okteto cluster. Okteto will connect your local SSH agent with the cluster. For example, this lets you clone any private repository as part of your manifest execution as long as your local agent has the proper ssh key configured |
Executed commands will be executed using bash unless the
--no-bash
flag has been specified.
Resources annotated with
dev.okteto.com/policy: keep
will not be affected by the destroy action.
doctor
Generates a doctor file with the okteto logs for a given development container:
$ okteto doctor [devName]
The doctor
command should be run from the folder where you ran okteto up
.
The doctor file contains:
- The
okteto.log
- The syncthing logs of your development container
- A summary of your development container manifest
- A metadata file with information about your host machine's OS and architecture
The doctor file is a handy way to collect all the okteto logs. Use it when filing an issue or asking the Okteto community for help.
down
Deactivates your development container, stops the file synchronization service, and restores your previous deployment configuration for a given development container.
$ okteto down [devName]
The down
command should be run from the same location as okteto up
.
Options | Type | Description |
---|---|---|
--file | (string) | The path to the okteto manifest (default "okteto.yaml") |
--namespace | (string) | The namespace to use (defaults to the current okteto context namespace) |
--context | (string) | The context to use (defaults to the current okteto context) |
--volumes | (bool) | Remove persistent volumes where your local folder is synched on remote |
endpoints
List the public endpoints of your development environment.
$ okteto endpoints
Options | Type | Description |
---|---|---|
--output | (string) | Output format. One of: ['json', 'md'] |