Deploying An Existing Application Using Okteto Cloud
Tags: fastapi, python, okteto, kubernetes
Published: 2021-04-20 10:46:00

---
title: Deploying An Existing Application Using Okteto Cloud
published: true
description: In this article, we explain the process of deploying an existing application to Okteto from the Okteto CLI.
tags: fastapi, python, okteto, Kubernetes
cover_image: https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/cover.png
---

Fast deployment of applications is an attribute Okteto boasts of. The deployment of applications from the Okteto dashboard is easy and fast as it requires one click on the deploy button without having to deal with the complexities of CLIs, manifests, etc. Applications deployed in Okteto are automatically secured using HTTPS and can be tested, shared, and used by the public.

In the [previous blog post](https://dev.to/okteto/building-and-deploying-a-fastapi-application-in-okteto-cloud-15d5), you learned how to build a FastAPI CRUD application and deployed it to Okteto using the Okteto CLI tool. In this tutorial, you will be learning how to deploy the application directly from your Okteto dashboard.
## Initial Setup

Start by creating a fork of the application from [GitHub](https://github.com/okteto/fastapi-crud) and then clone it locally. In your local clone, set it up using the following commands:

```console
$ cd fastapi-crud
$ python3 -m venv venv && source venv/bin/activate
(venv)$ pip install -r requirements.txt
```

Verify that the setup is complete by running:

```console
python3 main.py
```

## Initial Deployment

In the [previous post](https://dev.to/okteto/building-and-deploying-a-fastapi-application-in-okteto-cloud-15d5), you defined an Okteto stack file to facilitate the deployment of your application from the CLI tool. In this section, you will be deploying the application from the dashboard.

However, before deployment, you need to reassign the repository where Okteto will store your application images.

Your current `okteto-stack.yaml` file is similar to the code below:


```yaml
name: fastapi-crud
services:
  fastapi:
    public: true
    image: DOCKERHUBUSERNAME/fastapi-crud:latest
    build: .
    replicas: 1
    ports:
      - 8080
    resources:
      cpu: 100m
      memory: 128Mi
```

On line 5, modify the `image` value from:

```yaml
image: DOCKERHUBUSERNAME/fastapi-crud:latest
```

to: 

```yaml
image: okteto.dev/fastapi-crud:latest
```

In the code block above, you renamed the storage location of your application's image from your dockerhub to Okteto's repository.

### What's the okteto.dev repository ?

The `okteto.dev` repository is a container registry hosted in Okteto Cloud that allows every user to have its own space to store its container images. It's fully integrated with the rest of Okteto. In the previous post, we were using Docker Hub. Here, we are switching to Okteto's so our application deploys faster, and with fewer external dependencies.

Next, save the changes and commit the changes to GitHub:

```console
(venv)$ git add okteto-stack.yaml
(venv)$ git commit -m "Update image repository"
(venv)$ git push
```

With the stack file updated, proceed to your Okteto dashboard to deploy the application:

![Okteto Dashboard](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/dashboard.png)

Click on the **Deploy** button. A popup will appear, fill in the **Repository URL** and optionally, the branch name (here we are using *main*).

![Deploy Button](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/deploy.png)

Next, click on the deploy button. Okteto automatically retrieves, builds, deploys, and starts your application.

![Deployed Application](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/deployed.png)

## Adding A New Route

Let's update the application by adding a route for adding bulk recipes.

Open `app/api.py` with your favorite editor and add another route just below the POST route. Start by importing the `List` wrapper from `typing` before adding the new route:

```py
from typing import List

...

@app.post("/recipes", tags=["Recipe"])
def add_bulk_recipe(bulk_recipe: List[RecipeSchema] = Body(...)) -> dict:
    for recipe in bulk_recipe:
        recipe.id = len(recipes) + 1
        recipes.append(recipe.dict())

    return {            
        "message": "Recipes added successfully"    
    }

```

Test the new route from your terminal:

```console
(venv)$ curl --request POST \
  --url http://0.0.0.0:8080/recipes \
  --header 'Content-Type: application/json' \
  --data '[
	{
		"name": "Donuts",
		"ingredients": [
			"Flour",
			"Milk",
			"Sugar",
			"Vegetable Oil"
		]
	},
	{
		"name": "Creamy Donuts",
		"ingredients": [
			"Flour",
			"Milk",
			"Sugar",
			"Vegetable Oil",
			"Irish whipped cream"
		]
	}
]'
```

You will get a response similar to the one below:

```json
{
  "message": "Recipes added successfully."
}
```

Commit the new change in the `app/api.py` file into a new branch:

```bash
(venv)$ git checkout -b bulk-recipes && git add app/api.py
(venv)$ git commit -m "Add bulk recipes"
(venv)$ git push -u origin bulk-recipes
```

Verify that the new branch is available in your GitHub repo before going to the next step.

## Redeploying

Once again, login into your Okteto dashboard and click on the redeploy button:

![Redeploy Button](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/redeploy.png)

Change the branch from `main` to `bulk-recipes` and deploy:

![New Branch](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/new-branch.png)

You can see the branch you selected in the dashboard. When redeploying, Okteto will retrieve the latest changes from the branch, rebuild your application's containers (using the [Okteto build service](/blog/buildkit-as-a-service-in-okteto-cloud/)) and redeploy your application.

![bulk-recipes branch](https://okteto.com/blog/deploying-an-existing-application-with-okteto-cloud/bulk-recipes-app.jpg)

Test the new route by replacing `deployedapp` from previous requests with the live application url. From your terminal, run the command:

```console
(venv)$ curl --request POST \
  --url https://deployedapp.cloud.okteto.net/recipes \
  --header 'Content-Type: application/json' \
  --data '[
	{
		"name": "Donuts",
		"ingredients": [
			"Flour",
			"Milk",
			"Sugar",
			"Vegetable Oil"
		]
	},
	{
		"name": "Creamy Donuts",
		"ingredients": [
			"Flour",
			"Milk",
			"Sugar",
			"Vegetable Oil",
			"Irish whipped cream"
		]
	}
]'
```

You will get a response similar to the one below:

```json
{
  "message": "Recipes added successfully."
}
```

## Conclusion

In this article, you deployed an application directly from the Okteto dashboard and redeployed another new branch application version. The deployment was done with minor changes to the Okteto stack file, demonstrating the adaptability of the Okteto stacks. Additionally, Okteto can perform the deployment from different branches from the CLI tool. You can find the code from this article on [GitHub](https://github.com/Okteto/fastapi-crud/tree/bulk-recipes)

Get started with [Okteto](https://okteto.com) for free today to begin deploying your application in one click.