Kubernetes Assignment 1

Deployment of a micro-services application on K8s

·

3 min read

Kubernetes Assignment 1

This is an Assignment No. 1 for Batch 4 on Kubernetes. Let's complete this assignment...

About the project:-

For this assignment, we have to create microservices of Python Flask as the backend and MongoDB as the database.

Steps:-

  1. Setup K8s cluster using Minikube

  2. Deploy backend Micro-Services(Flask-App)

  3. Expose the backend app using the service

  4. Deploy database Micro-Service(MongoDB)

  5. Integrate Persistent Volume and Persistent Volume Claim

  6. Integrate microservices

1- Setup K8s cluster using Minikube

As we already setup minikube cluster we will go directly to step 2. Click here(LINKTODAY21) to learn how to install minikube. After installation start the Minikube using minikube start command.

2- Deploy backend Micro-Services(Flask-App)

First, clone the repository into the local repository. Use the git clone https://github.com/amitvpawar/microservices-k8s.git command.

Repository Link:- https://github.com/amitvpawar/microservices-k8s.git

Create deployment for the backend app. Go to the k8s directory and use kubectl apply -f taskmaster.yml command

3- Expose the backend app using the service

Create a service for the same to access from outside the cluster using kubectl apply -f taskmaster-svc.yml command.

We can access our backend as it is ready. To access it we need a URL. For URL use minikube service list and select url given for deployment.

If you use URL/tasks then it will throw an error as we don't have any Database yet. Refer app.py.

4- Deploy database Micro-Service(MongoDB)

Now create a deployment for MongoDB using kubectl apply -f mongo.yml command. Check pod is created or not using kubectl get pods command.

5- Integrate Persistent Volume and Persistent Volume Claim

Now it's time to persist our data for further use. To do so we'll use Persistent Volume and claim it for our database using Persistent Volume Claim. Use the following commands to do the same.

kubectl apply -f mongo-pv.yml command to create and attach the Persistent Volume to our database created earlier.

kubectl get pv command to list Persistent Volume created.

kubectl apply -f mongo-pvc.yml command to claim Persistent Volume for our database use(bind)

6- Integrate microservices

We couldn't face an Internal Server Error after creating the database.

Access URL/tasks to view tasks added to the database.

Now we will test our application by adding some tasks.

To add tasks use curl -d '{"task":"ANY_TASK"}' -H "Content-Type: application/json" -X POST http://192.168.49.2:30007/task command.

Now access your tasks from the URL you have. You can access your database and see the tasks present in it.

Add one more task and check whether it's shown in tasks or not.

This is all about how to use microservices in the K8s cluster with Minikube.

Thank you so much for taking the time to read till the end! Hope you found this blog informative.

Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

Special Thanks to Shubham Londhe Bhaiyya for this assignment.

Happy Learning :)