Build a Flask Love Calculator App with Docker and Kubernetes: A Step-by-Step Guide

Build a Flask Love Calculator App with Docker and Kubernetes: A Step-by-Step Guide

Description :

Discover our Flask Love Calculator App, a fun and interactive web application designed to calculate love compatibility between two individuals. Built using Flask, a popular Python web framework, this app combines sleek design with advanced algorithms to deliver accurate results. It’s containerized with Docker for seamless deployment and orchestrated using Kubernetes for scalability.

Perfect for tech enthusiasts and learners exploring Python web development, Docker, and Kubernetes, this project showcases the power of microservices architecture and cloud-native technologies. The app features a responsive UI, customizable logic, and real-time deployment capability.

Whether you’re looking for a fun coding project or a hands-on DevOps challenge, our Flask Love Calculator is your ideal choice! Learn how to integrate NodePort services, create YAML configuration files, and efficiently deploy applications in Kubernetes. Explore it now!

git clone : https://github.com/Safiakhatoon767/love_flask_calculator.git

vim config.yml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

nodes:
  - role: control-plane
    image: kindest/node:v1.31.2
  - role: worker
    image: kindest/node:v1.31.2
  - role: worker
    image: kindest/node:v1.31.2

docker build -t flask_love_calculator .

docker run -d -p 5000:5000 flask_love_calculator

docker logs 4ea3eb34d373

http://18.221.137.171:5000

docker stop 4ea3eb34d373

docker remove 4ea3eb34d373

go to docker hub:

go to account setting

then Personal access tokens

https://hub.docker.com/repository/docker/safiakhatoon280/flask_love5000_calculator/general

in password you gave token

docker images

docker tag flask_love_calculator safiakhatoon280/flask_love5000_calculator:latest

docker push image safiakhatoon280/flask_love5000_calculator:latest

vim namespace.yml

kubectl apply -f namespace.yml

apiVersion: v1
kind: Namespace
metadata:
  name: love-calculator-namespace

vim service.yml

kubectl apply -f service.yml -n love-calculator-namespace

apiVersion: apps/v1
kind: Deployment
metadata:
  name: love-calculator-deployment
  namespace: love-calculator-namespace
spec:
  replicas: 2
  selector:
    matchLabels:
      app: love-calculator
  template:
    metadata:
      labels:
        app: love-calculator
    spec:
      containers:
        - name: love-calculator-container
          image: flask_love_calculator:latest  # Change this to your actual image name if needed
          ports:
            - containerPort: 5000

vim deployment.yml

kubectl apply -f deployment.yml -n love-calculator-namespace

vim pod.yml

kubectl apply -f pod.yml -n love-calculator-namespace

apiVersion: v1
kind: Pod
metadata:
  name: love-calculator-pod
  namespace: love-calculator-namespace
spec:
  containers:
    - name: love-calculator-container
      image: safiakhatoon280/flask_love5000_calculator:latest
      ports:
        - containerPort: 5000

vim service.yml

kubectl apply -f service.yml -n love-calculator-namespace

apiVersion: v1
kind: Service
metadata:
  name: love-calculator-service
  namespace: love-calculator-namespace
spec:
  selector:
    app: love-calculator
  ports:
    - port: 80          # Cluster-wide port
      targetPort: 5000  # Flask container port
      protocol: TCP
      nodePort: 30001   # External port on the node
  type: NodePort

sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0

kubectl get services -n love-calculator-namespace

kubectl describe service love-calculator-service -n love-calculator-namespace

kubectl port-forward service/love-calculator-service -n love-calculator-namespace 5000:80 --address=0.0.0.0

http://3.142.151.123:5000/

Conclusion

Building a Flask Love Calculator app is not just a fun project but also a great way to learn essential concepts in Python development, Docker containerization, and Kubernetes orchestration. This project combines creativity and technology, making it an excellent addition to your portfolio or learning journey.

If you’re ready to take your skills to the next level, don’t forget to check out the source code and Docker image linked below:

#Python #Flask #Docker #Kubernetes #WebDevelopment #DevOps #Learning