Deploy a Flask Application in Kubernetes.

Rukmal Senavirathne
2 min readFeb 25, 2024

This Flask App deployment completely running on a local machine using minikube and kubectl.

Minikube — Minikube is a tool that creates a Kubernetes cluster in a local machine to run a single-node Kubernetes cluster. Minikube tool is useful for development, testing, and learning purposes.

Kubectl — kubectl is a CLI that is used for interacting with the Kubernetes cluster. It allows to deployment and managing the deployment like view logs, scale deployment, and perform administrative tasks within the Kubernetes cluster.

The Flask application code is published in,

https://github.com/rukmalaiteam/Flask

Deployment steps,

Files for the following steps are in the GitHub repository I provided above.

  1. Containerize the Flask Application — create a Dockerfile for Flask application and create a docker image.
docker build -t flask-app-1 .

2. Setup Kubernetes cluster — In this example, I am using minikube. There are other alternatives such as EKS (Elastic Kubernetes Service) in AWS, GKE (Google Kubernetes Engine) in GCP, and AKS (Azure Kubernetes Service) in Azure.

minikube start

3. Create Kubernetes Deployment — Using kubectl we can create Kubernetes deployment. Create deployment.yaml file and it specifies how to run Flask applications like docker image to use, and resource allocation for the application.

4. Create Kubernetes Service — Kubernetes service is used to expose Flask applications to external traffic. Create service.yaml file to specify the configuration.

5. Using kubectl create the deployment and service.

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

6. Verify deployment.

kubectl get deployments

It will show,

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
flask-deployment 4/4 4 4 31s

check running pods also using,

kubectl get pods

7. Access the Flask application.

minikube service flask-service - url

It will display the URL for the Flask application.

8. Check minikube dashboard.

minikube dashboard

Resources,

https://kubernetes.io/docs/tutorials/

--

--

Rukmal Senavirathne

Graduated from the Department of Computer Science and Engineering at the University of Moratuwa.