Creating a sample Python Flask application
We’ll start by creating a simple application. The provided Python code defines a basic Flask web application with a single route (“/”) that returns the string “Hello from the Python Flask App!” when accessed, and it runs the application on host ‘0.0.0.0’ and port 5000 when executed directly.
# app.py
# Importing the Flask class from the flask module
from flask import Flask
# Creating an instance of the Flask class with the name of the current module (__name__) as argument
app = Flask(__name__)
# Defining a route for the root URL ("/") that responds to HTTP GET requests
@app.route('/')
def hello():
# Returning a string "Hello from Python Flask App!" as the response
return "Hello from Python Flask App!"
# Entry point of the application. This block ensures that the app is run only if executed directly, not imported as a module.
if __name__ == '__main__':
# Running the Flask application on the specified host ('0.0.0.0') and port (5000)
app.run(host='0.0.0.0', port=5000)
Also create a requirements.txt file as below.
Flask==2.0.2
Python Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development workflow and ensures consistent, reliable deployments. This article demonstrates deploying a sample Python Flask application on a Kubernetes cluster using Minikube.