Kubernetes Projects

High-Level Project: Deploying a Python Flask Application with Redis on Kubernetes Using Docker.

In this Project, I deployed a Python Flask Application that uses Redis for caching on Kubernetes cluster using Docker.

Breaking down the project into sections

Project Architecture:– The Architecture consists of a Flask Application and a Redis database running in separate Docker Containers within a Kubernetes cluster.

  • Flask Application: A simple web server that uses Redis for caching.
  • Redis: An in-memory data structure store used as a cache.

Project Architecture —-(As pictured)
Project Setup:- First I setup the project Environment, by installing Docker, Kubectl, Minikube and Helm
I used Helm for easier management of the kubernetes applications
Dockerising the Flask Application:– For this part of the Project I created a Flask application that connects to Redis Using Python. you can find my Code at my Github HERE.
Then I created a Dockerfile to containerize the application. This involved, using an official python 3.9 image from the Dockerhub, setting the work directory, copying a requirements.txt file into the image. Installing the Python dependencies, copying the application code into the image. Exposing port 5000 for the Flask app and finally running the app.
Setting up Kubernetes Manifests:- To set up the manifest I created several .Yaml files.

  • namespace.yaml
  • redis-deployment.yaml
  • redis-service.yaml
  • flask-deployment.yaml
  • flask-service.yaml
    After I created each file I ran them through “yamlchecker.com” as a form of code check try and eliminate any errors there may have been.

Deploying to Kubernetes:- To deploy to kubernetes I made sure Minikube was running by using the command: Minikube start.

Then i proceeded to deploy the yaml templates
Apply Namespace :- kubectl apply -f namespace.yaml

Deploy Redis:-“kubectl apply -f redis-deployment.yaml” and then “kubectl apply -f redis-service.yaml”
and finally,

Deployed the Flask application:- “kubectl apply -f flask-deployment.yaml” and “kubectl apply -f flask-service.yaml”

Accessing the Application:– To access and makes sure my Flask application was running correctly I had to retrieve the External IP address using “minikube service flask-service -n flask-redis-namespace”
Using the IP address I was able to access the application and see it working as the application itself increments a counter in Redis, every time the Root endpoint is accessed which demonstrates basic inter-communication in a Kubernetes environment.

From this project I gained an amass of knowledge and skills, I am now able to create and push Dockerized containers to Kubernetes, Deploy, access and troubleshoot the containers using kubectl. This is because I faced some challenges during the project where the Yaml templates i had created were not correctly indented to work in kubernetes, even though i checked them using the yamlchecker website, though this was a relatively easy fix using my IDE. Another issue that arose was my container did not deploy correctly due to the error in the yaml file. So I used to kubectl commands to troubleshoot and rectify the issue.
Overall I found this project fun and I am eager to move onto the next one!