DEV Community

Cloudev
Cloudev

Posted on

Deploying a Flask Application to Kubernetes Using Minikube

I have recently been spending time tinkering with Kubernetes and exploring how container orchestration works in practice. To get hands on experience, I set up a local cluster using Minikube and started experimenting with deploying simple applications.
Project Overview
The goal of this project is to:

  • Build a simple Flask web application
  • Package it in a container using Docker
  • Deploy it to a Kubernetes cluster
  • Expose the application so it can be accessed from a browser

This setup runs locally using Kubernetes through Minikube.
Architecture

The deployment follows a simple Kubernetes architecture:

  • User → Kubernetes Service → Deployment → Pods → Flask Container
  • Deployment manages the application pods
  • Pods run the containerized Flask application
  • Service exposes the application to the outside network

Project Structure

The repository contains the following files:

kubernetes-flask-app

├── app.py
├── requirements.txt
├── Dockerfile
├── deployment.yaml
├── service.yaml
└── README.md

  • app.py A simple Flask application that returns a message when accessed.
  • requirements.txt Contains the Python dependencies required to run the application.
  • Dockerfile Defines how the Flask application is packaged into a container image.
  • deployment.yaml Defines the Kubernetes deployment and manages the application pods.
  • service.yaml Creates a Kubernetes service to expose the application.

Running the Project
1. Start Minikube
Start your local Kubernetes cluster.

  • minikube start

Verify the cluster is running.

  • kubectl get nodes 2. Build the Docker Image Configure your environment to use the Docker daemon inside Minikube.

eval $(minikube docker-env)

Build the container image.

docker build -t flask-k8s-app .
3. Deploy the Application
Create the deployment in Kubernetes.

  • kubectl apply -f deployment.yaml

Check the running pods.

kubectl get pods
4. Expose the Application

Create a Kubernetes service.

  • kubectl apply -f service.yaml

To access the application:

  • minikube service flask-service

Your browser will open the application.

What This Project Demonstrates

This project helps demonstrate core DevOps and cloud concepts:

  • Containerization using Docker
  • Container orchestration using Kubernetes -Local Kubernetes development using Minikube
  • Deployments and services in Kubernetes

Repository

You can find the full project source code on GitHub:
https://github.com/Copubah/kubernetes-flask-app

Top comments (0)