Develop your Application in Okteto Cloud

This tutorial will show you how to use Okteto to develop your applications in Kubernetes. Okteto lets you code locally and see the results instantaneously in Kubernetes, the Cloud Native way.

If you haven’t deployed your first application in Okteto Cloud, we recommend that you first complete our 5-minute getting started guide, since this guide depends on having a dev version of the sample application deployed in Okteto Cloud.

Step 1: Install the Okteto CLI

The Okteto CLI lets you develop your applications directly in Kubernetes while taking advantage of well-known tooling like native programming language compilers, hot reloads or IDE debuggers. Code locally. Update your application in Kubernetes in seconds. No commit, build or push required.

The Okteto CLI is open source, and the code is available at Github. Check it out and star it to show your support 🤗!

If you haven’t done it yet, install the Okteto CLI running the following command in your local shell:

MacOS/Linux:

1
$ curl https://get.okteto.com -sSfL | sh

Windows:

1
$ wget https://downloads.okteto.com/cli/okteto-Windows-x86_64 -OutFile c:\windows\system32\okteto.exe

Step 2: Start your development environment in Kubernetes

Open a local shell, and navigate to the folder where you cloned the sample application’s code. Once you’re there, run the okteto up command to create your development environment:

1
$ okteto up
1
2
3
4
5
6
7
8
 ✓  Development environment activated
✓ Files synchronized
Namespace: cindy
Name: hello-world
Forward: 8080 -> 8080
2345 -> 2345

okteto>

The okteto up command starts a Kubernetes development environment, which means:

  • The Go Sample App container is updated with the docker image okteto/golang:1. This image contains the required dev tools to build, test and run the Go Sample App.
  • A file synchronization service is created to keep your changes up-to-date between your local filesystem and your application pods.
  • A volume is attached to persist the Go cache in your Kubernetes development environment.
  • Container ports 8080 (the application) and 2345 (the debugger) are forwarded to localhost.
  • You have a remote shell in the development environment. Build, test and run your application as if you were in your local machine.

To run the application, execute in the remote shell:

1
okteto> go run main.go
1
Starting hello-world server...

Open your browser and go to the URL of the application to test it.

You can get the URL by logging into Okteto Cloud and clicking in the application’s endpoint.

Step 3: Develop directly in Kubernetes

Open the file main.go in your favorite local IDE and modify the response message on line 17 to be Hello world from Okteto!. Save your changes.

1
2
3
func helloServer(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello world from Okteto!")
}

Okteto will synchronize your changes to your development environnment in Kubernetes. Cancel the execution of go run main.go from the remote shell by pressing ctrl + c. Rerun your application:

1
okteto> go run main.go
1
Starting hello-world server...

Go back to the browser, and reload the page. Your code changes were instantly applied. No commit, build or push required 😎!

Step 4: Debug directly in Kubernetes

Okteto enables you to debug your applications directly from your favorite IDE. Let’s take a look at how that works in VS Code, one of the most popular IDEs.

Cancel the execution of go run main.go from the remote shell by pressing ctrl + c. Rerun your application in debug mode:

1
okteto> dlv debug --headless --listen=:2345 --log --api-version=2
1
2
API server listening at: [::]:2345
2019-10-17T14:39:24Z info layer=debugger launching process with args: [/okteto/__debug_bin]

Open the Debug extension and run the Connect to okteto launch configuration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to okteto",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "/okteto",
"port": 2345,
"host": "127.0.0.1"
}
]
}

Add a breakpoint on main.go, line 17. Go back to the browser, and reload the page. The execution will halt at your breakpoint. You can then inspect the request, the available variables, etc…

Next steps

Congratulations, you just developed your first application in Okteto Cloud 🚀.

Okteto helps you move your entire development workflow to Kubernetes. This way you can:

  • Eliminate integration issues by developing the same way your application runs in production.
  • Uninstall Docker or Minikube. No more cpu cycles wasted in your machine.
  • Hardware and network just limited by the power of the cloud!
  • Your development endpoints are always available. No need to expose your local machine to the internet through remote tunnels.

Now it is time to confidently commit your code changes, send a PR, and use your CI/CD system to deploy to production 💪.

You can have several namespaces in Okteto Cloud, one to develop your applications, and another one to run your applications.

Okteto uses the okteto.yml file to determine the name of your development environment, the docker image to use and where to upload your code. Check the Okteto manifest docs to customize your development environments with your own dev tools, images, and dependencies to adapt Okteto to your own application.

Got questions? Join the conversation in our Kubernetes Slack channel! If you don’t have a Kubernetes slack account yet, sign up here. We’d love to hear from you 😄.