A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/devops/how-to-deploy-flask-app-on-kubernetes/ below:

How to Deploy Flask App on Kubernetes?

How to Deploy Flask App on Kubernetes?

Last Updated : 23 Jul, 2025

A lightweight Python framework providing simplicity and flexibility in development, Flask can be utilized to create web applications. In contrast, Kubernetes is an effective framework for container orchestration that facilitates the deployment, scaling, and management of containerized applications. While Kubernetes makes sure these apps function perfectly by managing resources and processing traffic efficiently, Flask allows you to construct web pages and handle requests. When taken together, they provide an effective combination that streamlines and improves reliability for developing, launching, and managing web applications at scale. By referring to this blog you will get clear knowledge about deploying the flask app in Kubernetes.

Step by step to Deploy Flask App on Kubernetes

Step 1: Create the repository and push the code into the repository.
Step 2: Here is my GitHub python-flask repository.

Step 3: Clone the repository into vm and list the files. Here are the my files in the repository.

Build a container image with Docker

Step 4: Here is the Dockerfile in the repository. You can write your own Dockerfile as per your requirements.

FROM python:3.9-slim
WORKDIR /usr/src/app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
ENV FLASK_APP=app.py
CMD ["flask", "run", "--host=0.0.0.0"]

Step 5: We need to build the docker image by using the below command. For your reference refer the below image.

docker build -t <image-name>:<tag> .

Step 6: After successfully build the image list the docker images by using the below command. For your reference refer the below image. Here i have pushed the docker image into docker hub.

docker images
Create the Deployment and Service

Step 7: Create the deployment file here is the my deployment file you can can write your own deployment file as per the your requirements.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flask
  template:
    metadata:
      labels:
        app: flask
    spec:
      containers:
      - name: flask-container
        image: larasai/flask-pyhton
        ports:
        - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: flask-service
spec:
  selector:
    app: flask
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 5000
  type: NodePort
  1. Deployment:
  2. Service:

Step 8: Create the deployment file by using the below command the deployment and service created successfully in the Kubernetes cluster. For your reference refer the below image.

kubectl apply -f <deployment-file-name.yaml>

Step 9: List the deployments and services of the flask application. For your reference refer the below image.

kubectl get deployment
kubectl get pods

List the service of the flask deployment by using the below command.

kubectl get svc

Step 10: Access the application by using the nodeport. Refer the below image for your reference the flask application successfully deployed and accessed successfully.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4