Deploy Cloud Native Voting App on Kubernetes:
Introduction:
In this project we will be deploying cloud native voting app on kubernetes, this application has react as front end , golang as API and mongodb as a database, The concept behind this project is that whenever user came and cast its vote data should be fetch from golang API that data should be update in mondo db database.
Architecture Diagram:
MongoDb:
We will be using three pods for our database mongodb service one pod will be primary which will be in read and write state while two pods will be secondary which will have complete replica of primary pod but only in read mode, the replica pods can become primary pod also in case primary pods fails so fault tolerance also achieve through it.
API:
We will create API through deployment and use two pods for this and will expose service through service type load balancer.
Front End:
The APIs will get the data from front end, front end will also have two pods. We will also expose it through service type load balancer.
Lets start the project:
We will be using Amazon EKS to deploy the application on kubernetes:
Once you click on create cluster then select option add on:
And search for amazon EBS add on:
This is to create EBS volume automatically for PODs in cluster.
Once EBS added go to compute option to add node groups and select t2.medium instances there:
Install kubectl on your local system to interact with kubernetes cluster:
Now add your cluster info in kubectl config file so that kubectl able to interact with kubernetes cluster:
Along with kubectl you should have aws cli in your local system so that it interact with AWS for that create IAM user in AWS and then create its secret and access keys and configure those keys in your system via aws configure:
Now clone the manifest file from below github link:
Our nodes are ready now we will create pods for mongo db through mongo manifest file:
But first create the new namespace in cluster:
Now apply the manifest file of mongo it will create three pods along with three persistent volumes of pods,
Benefit of using PVs (persistent volume for database pods)
Once pods are created you will notice that extra 1 gb persistent volume also created for each pod, kubernetes scheduler created two pods in one 1 node and 1 pod in other:
Now we will expose our mongo db pods using service, we will create headless service because we are not gonna expose mongo database to external world, just to expose it for rest API:
Create service for mongodb:
If you do not want to type namespace again and again with kubectl command use below command:
Now we we will set mongo 0 to our primary pod and other two as secondary:
Use these all command in the mongo shell to make the mongo-0 pod as primary and mongo-1, mongo-2 as secondary:
Now we will create database in mongo-db so that we can insert data there:
I will put data of each programing language which will be in voting app:
These all commands can be find in readme section of github link:
Write now we have zero vote in each language:
So we will create front end so that when ever someone cast vote in font end it is deploy in mongodb through API.
First deploy the API:
To deploy the API we will create the secret file that hold the password and username for the database:
Now we are ready to deploy the API as well:
It will create two pods for API:
We need to expose these API by creating the load balancer service because need to expose API to outside cluster:
It have created load balancer for us:
Now we will deploy our front end which will get votes from the users:
It has created two pods for front-end also:
Now expose the front end using load balancer service:
It also created load balancer for front end:
Now access the front-end load balancer and cast some votes:
These vote will be seen in database:
Thats all in this project.