Hybrid development
Okteto offers two different approaches to service development: sync
or hybrid
mode. This mode is configured in your Okteto manifest and affects the behavior of okteto up
.
Sync
is the default mode and code changes made to the local filesystem are synchronized to the remote development container deployed in the cluster. Alternatively, hybrid
mode enables you to run the service in development locally while keeping the rest of the application components in the cluster.
Deciding which mode to use
There are situations when running a service locally is faster than synchronizing code with a remote development container. For example: when doing frontend-only development or when working in an IDE-heavy context (e.g. Java/Spring) where the IDE may be pre-configured to run tests, start services, and connect debuggers.
When using Okteto's hybrid
mode you can maintain your local development experience for the specific service you're working on while still leveraging the benefits of hosting the rest of your application's components in the remote development container.
Using
hybrid
might increase latency when accessing the rest of the services in the cluster.
How hybrid development works
To allow communication to and from the cluster and your local machine an SSH server is deployed in the remote development container. You can expose the local service to the services running in the cluster using the reverse
configuration for the development environment. If you want to forward a service running in the cluster to your local machine you can use the forward
configuration.
When using hybrid
mode the process running locally is designed to run with the same environment as the original service running in the cluster. To achieve this, the following environment variables are added to the local process running the service in hybrid
mode. This list is ordered from highest to lowest prevalence:
- Environment variables defined in the environment of the development container
- Environment variables defined in the original container spec
- Environment variables coming from configmaps defined in the original container spec
- Environment variables coming from secrets defined in the original container spec
- Environment variables defined in the container image
How to develop in hybrid mode
To enable hybrid
mode you only need to configure the necessary ports to expose the local service to the cluster network. This allows the components running in the cluster to communicate with the local service as if it was running directly in the cluster.
To do this you can make use of the reverse field in your Okteto manifest, which will expose the configured port of your local machine to the desired port on the development container.
dev:
frontend:
mode: hybrid
reverse:
- 3000:8080
workdir: ./frontend
command: ["yarn start"]
In this example we have configured the frontend
service to use mode: hybrid
. This means Okteto will redirect requests to the frontend service in the cluster to your local machine.
Okteto will execute (locally) the command defined in the command
field and in the directory specified in workdir
. To simulate the same environment as the original container, certain environment variables are autoinjected into the process running locally. More about which environment variables are added to the local process here. Additionally, anything exposed locally on port 8080
will be exposed on port 3000
of the development container. This makes it possible for other components running on the cluster to access the local service as if it were running remotely in the cluster.
You can find full samples of hybrid mode in the following links: