Kubernetes Using Cloud Shell: Deploy a Python Flask Application
In this tutorial, you use an Oracle Cloud Infrastructure account to set up a Kubernetes cluster. Then, you create a Python application with a Flask framework. Finally, you deploy your application to your cluster by using Cloud Shell. Key tasks include how to:
- Set up an authentication token.
- Set up a Kubernetes cluster on OCI.
- Build a Python application in a Flask framework.
- Create a Docker image.
- Push your image to OCIR.
- Use Cloud Shell to deploy your Docker application to your cluster.
- Connect to your application from the internet.

For additional information, see:
Before You Begin
To successfully perform this tutorial, you must have the following:
- A paid Oracle Cloud Infrastructure account. See Signing Up for Oracle Cloud Infrastructure .
- SSH support:
- A MacOS or Linux computer with
ssh
support installed. - A Windows machine with Git Bash installed. See Git for Windows.
- A MacOS or Linux computer with
1. Gather Required Information
Prepare the information you need from the Oracle Cloud Infrastructure Console.
2. Create SSH Encryption Keys
Create ssh
encryption keys to connect to your compute
instance.
You have generated the required encryption keys.
See Creating a Key Pair for more detailed information
on generating ssh
encryption keys.
3. Create your Virtual Cloud Network (VCN)
Setup a VCN to connect your Ubuntu instance to the internet. You configure all the components needed to create your virtual network.
To open a different port, replace 5000 in the last step with the port number.
4. Install your Ubuntu VM
Install an Ubuntu VM to host your applications. This is a Free Tier VM and using it is free, no cost forever.
5. Run a Python Application in a Flask Framework
Next, set up a Flask framework on your Ubuntu Linux VM and then create and run a Python application.
By default, Ubuntu 18.04 comes with Python3, but it does not come with virtualenv, Flask or Docker. To create your application with Flask, perform the following steps:
You have successfully created a local Python application in a Flask framework, on your Oracle Cloud Infrastructure VM.
References:
For more information on Flask, see Flask Documentation.
6. Build and Push your Python Flask Docker Image
Next, create a Docker image on your Ubuntu Linux VM and then push it to Oracle Cloud Infrastructure Registry.
Install Docker
Install Docker on your Oracle Linux VM.
This snap build requires all files that Docker uses, such as Dockerfiles, to be in $HOME or a sub-directory of it. Keep the files there, for commands such as
docker build
, docker save
and
docker load
.Build a Docker Image
Build a Docker image for your application.
Push your Docker image to OCIR
With your Docker image created, now you need to push it to OCIR.
View the OCIR Repository you Created
Congratulations! You created a Flask Python Docker image. Now you can create a Kubernetes cluster and deploy this image to the cluster.
7. Create your Kubernetes Cluster
Set up the Kubernetes cluster you will deploy your application to. You will use a wizard to set up your first cluster.
8. Manage your Kubernetes Cluster with Cloud Shell
You can access your Kubernetes cluster and manage your deployments from Oracle Cloud Infrastructure Cloud Shell (Cloud Shell). To do that, complete the following steps:
With your cluster configured, you are now ready to prepare your application for deployment.
9. Deploy your Docker Image to your Cluster with Cloud Shell
- Deployment: Pull and deploy the image from registry.
- Load Balancer Service: Make the application available with a public IP address.
Perform the following steps in Cloud Shell:
Create a Registry SecretYour load balancer may take a few seconds to load after issuing the command.
Clean up the Application
After you are done, clean up and remove the services you created.
What's Next
You have successfully created a Hello World Python application, deployed it to a Kubernetes cluster and made it accessible on the internet, using the Flask framework.
To explore more information about development with Oracle products check out these sites: