Skip to main content

Getting Started with Divert

This tutorial provides an introduction for using the divert option in Okteto Manifests. The divert feature enhances the deployment of your development container when using HTTP-based services.

Overview#

This tutorial makes use of a demonstration application that mimics a service catalog. The service catalog tracks services, their owners, and health information.

The original deployment contains only the most recent health data for each service in the catalog. This is helpful but it could be better.

A developer decides that health data for each service would be more helpful if it contained historical data. In this scenario, the developer adds a data store and changes the health-checking service to provide more data.

The developer uses the divert feature to develop the new feature side-by-side with the original application.

Let's get started!

Prerequisites#

Deploy application#

Deploying the service catalog sample application is as simple as...

$ okteto pipeline deploy --wait
✓ Pipeline 'catalog' successfully deployed

The okteto pipeline deploy command creates all of the necessary components for the service catalog sample application. The okteto-pipeline.yml file defines the steps to deploy the application. The --wait flag instructs the okteto pipeline deploy command to wait until the application is up and running (this could take about 2 minutes).

Once your pipeline is successfully deployed, visit Okteto Cloud. Your application will be available in a URL similar to https://catalog-chart-cindy.cloud.okteto.net. Visiting the URL will bring up the service catalog application with only the most recent health data available.

Original Application

Create development resources using Divert#

Now, you will change into the directory health-checker and run okteto up. The manifest for the health checker service contains the divert option.

name: health-checker
labels:
app.kubernetes.io/component: health-checker
image: okteto/golang:1
command: bash
sync:
- .:/usr/src/app
persistentVolume:
enabled: false
divert:
ingress: catalog-chart
service: health-checker
port: 8080

Adding the divert option alters how Okteto deploys the development container. The default behavior, without the divert option, will replace the target deployment with the dev container. This prevents you from using the original application without either bringing down the development container or deploying a duplicate of your application. When using the divert option your development container will be brought up alongside your original container. In addition, a duplicate of the specified ingress is provisioned so that you can use either endpoint. The original endpoint to access the original application and the duplicate endpoint to access your application as you develop. Try it out now!

$ cd health-checker
$ okteto up
✓ Images successfully pulled
✓ Files synchronized
Name: cindy-health-checker
URL: cindy-health-checker-cindy.staging.okteto.net
Welcome to your development container. Happy coding!
cindy:cindy-health-checker app>

At this point, Okteto has duplicated the health-checker service and the original deployment as a development deployment. Along with the development deployment, there is now a new URL similar to https://cindy-catalog-chart-cindy.cloud.okteto.net. Accessing the application with the development URL will divert all traffic bound to the health-checker service to your development deployment.

Edit application#

The application code already contains an advanced health checker client that has historical health data. Now, we need to make use of this newly developed advanced health checker. To do so we edit the file health-checker/cmd/main.go so that the health handler uses your advanced client.

Code Edit

Run modified application#

With our edits in place, it is now time to run the application in the development container. Build and run by typing go run cmd/main.go in the container.

cindy:cindy-health-checker app> go run cmd/main.go
go: downloading github.com/caarlos0/env v3.5.0+incompatible
go: downloading github.com/justinas/alice v1.2.0
go: downloading github.com/rs/zerolog v1.22.0
go: downloading github.com/rs/xid v1.2.1
{"level":"info","time":"2021-05-28T18:55:13Z","message":"listening on :8080"}

Now if you visit the development URL you can see the changes live. The original application is left untouched and is still available at the original URL.

Original Application

Application Architecture with Divert#

With the catalog application deployed, and the divert development container in place the resulting deployment is...

Application Divert Architecture