Okteto gives you instant cloud environments to code and collaborate. Write code using your favorite IDE, and see the results directly in the cloud. No commit or push required.
This tutorial will have you developing and deploying a Python app in less than 5 minutes. Hang on for a bit longer to learn more about the power of Okteto.
While you’re going through this tutorial, why don’t you join Okteto’s slack community and say hi 🤙?
You’ll use the CLI to create your Okteto Environments, provision databases and run your application.
Install the Okteto CLI by running the following command in your local terminal:
curl https://get.okteto.com -sSfL | sh
wget https://downloads.okteto.com/cloud/cli/okteto-Windows-x86_64 -OutFile c:\windows\system32\okteto.exe
The login command will automatically create an account for you in Okteto. It will also automatically create your personal Okteto Space. Okteto Environments and Databases launched in your space can only be accessed by you. They also share the same network, so they can talk to each other directly.
Okteto runs your application in an Environment. An Okteto Environment is a container that includes all the runtime components and developer tools you need to build and run your application. We offer pre-built development environments for the most popular software stacks, but you can also create and share your own.
Get a local version of the sample application by executing the following commands in your local terminal:
git clone https://github.com/okteto/cloud-samples
You now have a functioning git repository that contains a simple python 3 application and a
requirements.txt, which is used by Python’s dependency manager,
pip. The application we’re using in this tutorial consists of a flask app that allows you to vote for your favorite animals and stores the results in a Redis database.
First we need to provision the Redis database. Okteto provides three database services: Okteto Postgres, Okteto Redis and Okteto MongoDB. Run
okteto database redis in your local terminal to provision an instance of Okteto Redis into your Okteto Space. The command will print out the name and connection string of your database instance.
okteto database redis
Now start your Okteto Environment by running
okteto up in your local terminal:
okteto up command will create an Okteto Environment with a random name and configured for your application (you can customize this later by updating
okteto.yml). Your Okteto Environment will be active until you manually deleted it.
Every Okteto Environment has a unique public address. It will be accessible while your application is running and listening on port
Once the Okteto Environment is ready, start your application by executing the following commands in your Okteto Terminal:
pip install -r requirements.txt
Your application is now ready. Open your browser and go the URL of the application. You can get it from the
okteto up command, or by logging into Okteto and clicking in the application’s endpoint.
Place a few votes on your favorite animal to see try out the application. Congratulations, you just deployed your first Okteto Application 🚀!
Now things get more exciting. When your Okteto Environment starts, a file synchronization service is created to automatically keep your changes up to date between your local filesystem and your Okteto Environment. With Okteto, you can still use your local IDE, even when developing directly in the cloud.
vote/app.py in your favorite IDE and modify the
getOptions function with the following code, and save your file:
Go back to your Okteto Terminal and notice that flask already detected the code changes and reloaded your application.
Go back to the browser, and reload the page. Notice how your changes are instantly applied. No commit or push required 😎!
Now that you are happy with your changes, it’s time to run your updated application with the
okteto run command. Instead of launching an Okteto Environment and synchronizing your files, the
okteto run command automatically deploys a container into your Okteto Space.
Let’s build a Docker image with your latest changes. Press
ctrl + c and
ctrl + d in your Okteto Terminal to go back to your local terminal, and execute the following command to build your docker image and push it to Docker Hub:
docker build -t <hub-user>\vote
If you don’t have access to Docker Hub, you can use
okteto/vote:0.1.0instead of your own docker image to complete this step.
Once your image is ready, run the following command to deploy your container:
okteto run <hub-user>\vote
After a couple of seconds, your application will be ready. Go back to the browser and reload the page to see your new docker container up and running.
okteto runonly supports images from public docker repositories.Contact us if you’re interested in support for private images
You now know how to create an Okteto Environment, deploy your application on it, develop it directly in the cloud and deploy the final container.
Notice that an
okteto.yml has been generated in your folder. Okteto uses that manifest to determine the name of your Okteto Environment, the docker image to use and where to upload your code. You can edit it to customize your Okteto Environment. This will let you spin an Okteto Environment already configured with your own dev tools and dependencies.
Visit our samples repository to learn more about how to use Okteto to speed up your development.