Microservice Application Deployed On Kubernetes.

Passionate AWS Developer | DevOps Engineer with a strong background in cloud architecture and solutions engineering. Leveraging the power of Amazon Web Services (AWS), knowledge of the AWS global infrastructure, design and implement robust cloud-based solutions that align with clients' specific needs.
Here Microservice application is deployed on Kubernetes using Flask app and Mongodb.
Microservices allow a large application to be separated into smaller independent parts, with each part having its own task. To serve a single user request, a microservices-based application can call on many internal microservices to compose its response.
Here I am using Killercoda tool for the kubernetes. Killercoda is an interactive learning platform which allows everyone to access Linux Kubernetes based environments just in their browser.
Following are the steps to deploy the microservice on Kubernetes.
First of all clone the code from Github.
git clonehttps://github.com/akarsha-prasad/microservices-k8s.gitgit clone <github url>

- Go into the flask-api through ls command.
The Docker file for flask app. The docker image is built and pushed to Dockerhub repo.
FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENV PORT 5000
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
~
docker build . -t mongo
docker run -d -p 5000:5000 mongo:latest
docker tag mongo 291019955/mongo:latest
docker push 291019955/mongo:latest

Navigate to project's root directory.
cd k8smongo.yml file (deployment file)

Create a Kubernetes service deployment by running the following command.
kubectl apply -f <yaml filename> kubectl apply -f mongo.yaml kubectl apply -f mongo-pv.yml kubectl apply -f mongo-pvc.yml kubectl apply -f mongo-svc.ymlNow the deployment file, service file, persistentVolume and persistentvolumeclaim will be created one by one.
To see the running pod, run the command:
kubectl get pods

Enter into the running pod by following command.
kubrctl exec -it <running-pod-name> bashRun
mongoshcommand to connect to mongodb database

Through
exitcommand, come out of this.To access the deployment from outside the cluster create a service file. taskmaster service file

Create a taskmaster deployment and service file by running the following commands, pod will be created.
kubectl apply -f taskmaster.yml kubectl apply -f taskmaster-svc.yml

Check the running pods by command:
kubectl get podsNow we can see two pods running- mongo and taskmaster.

To get all service and deployment details.
kubectl get deployments,servicesTo access this deployment using command:
curl https://<ip>:<node-port>

To insert data in the mongodb, follow the command:
curl -d '{"task":"Complete the assignment"}' -H "content-type:application/json" -X POST http://127.0.0.1:30007/task curl -d '{"task":"come to join train with shubham"}' -H "content-type:application/json" -X POST http://127.0.0.1:30007/task


- Data is inserted into mongodb.

To see the data, run the command:
curl http://127.0.0.1:30007/tasksSee the result.

Deployment of microservice application - flask app and mongodb is done successfully on k8s.




