Git Product home page Git Product logo

nuageup_tech's Introduction

The hello world Flask application

The repository includes a Flask hello world application along with its Dockerfile for building Docker images. It also contains all the necessary manifests for deploying the application on a Kubernetes cluster, along with the Helm chart for the application.

this Readme file contains the detailed instructions on how to deploy and test the application.

Prerequisites Tools

To test and deploy this application, you will need the following tools:

Local Testing

To start testing this application, you need to create a virtual environment, install the required dependencies in it, and then run the application.

python -m venv .venv
source ./.venv/bin/activate

now you need to install the requirements in the virtual env

pip install -r requirements.txt

You can then start the app by running:

flask run --host 0.0.0.0 

Build Process

The application will be built using Docker. We will create a Docker image based on our Dockerfile, which contains the necessary steps to build our image.

To build the image, use the following command:

docker build -t your-registry/image-name:tag .

To push this image, you need to login to your registry using:

docker login

Then, push your image using:

docker push your-registry/image-name:tag

Replace your-registry, image-name, and tag with your actual registry, image name, and tag respectively.

Deployment

To deploy our application on a Kubernetes cluster, we will use Minikube to create a local Kubernetes cluster on our machine. We will start our cluster using the following command:

 minikube start --network-plugin=cni

You can test your cluster's status by running:

minikube status

Alt text

Next, we will deploy our application on the cluster by applying the different YAML files located in the manifests folder.

We can start by creating a namespace for our application using either of the following commands:

kubectl create namespace "namespace_name"

or

kubectl apply -f manifests/namespace.yaml

Then, we deploy the application by creating the deployment resource for our app:

kubectl apply -f manifests/deployment.yaml 

You can check the status of your deployment using:

Alt text as we can see 3 of 3 replicas of our app are ready

Self-Healing Mechanisms

After deploying our app using the deployment manifests, we can view the created pods using the following command:

kubectl get pods -n helloworld

This command shows that the deployment has successfully created 3 replicas of our application, ensuring high availability and self-healing capabilities in case of pod failures.

Alt text

If we manually delete one of these pods:

kubectl delete pod helloworld-845c7958d7-bzk9k -n helloworld

and then list our pods again, we will see that the deleted pod is in a terminating state. Shortly after, Kubernetes will automatically create a new replica of our pod, demonstrating the self-healing mechanism recovering from a pod deletion.

Alt text

Networking

To enable communication for our application, we need to create a service of type LoadBalancer by applying the service.yaml file. Additionally, for external communication, we need to create an Ingress rule using the ingress.yaml file.

Before creating the Ingress, ensure that you have a running Ingress controller. For Minikube, you can enable the Ingress Controller using the following command:

minikube addons enable ingress

Autosacling

To enable Horizontal Pod Autoscaling (HPA), you must first enable the Metrics Server on your Kubernetes cluster. For Minikube, you can enable the Metrics Server using the following command:

minikube addons enable metrics server

After enabling the Metrics Server, you can apply the hpa.yaml manifest to set up Horizontal Pod Autoscaling for your deployment.

Helm Chart Deployment

Another way to deploy our application and its required resources is by using the Helm chart located in the hello-world folder. A Helm chart is a way of packaging our Kubernetes application, and we will use Helm to install it with the following command:

helm install helloworld ./hello-world

To customize the deployment, you can modify the values in the values.yaml file of the Helm chart before installing it. This allows you to configure various aspects of your application deployment, such as resource limits, environment variables, and more.

CI/CD Pipeline

For our CI/CD pipeline, we used GitHub Actions to define our pipeline. We have three stages in our pipeline: a build stage, a test stage, and a deployment stage. The pipeline definition is located in the .github/workflows/deploy.yaml file.

Alt text Since we have no access to a Kubernetess cluster on a cloud provider in our deployment stage, we decided to test the deployment using Minikube. We create a Minikube cluster and deploy our app using the Helm chart. Then, we test if the deployment succeeded.

Alt text

nuageup_tech's People

Contributors

souheilbenslama avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.