Kubernetes Project : Micro-Services on Kubeadm

Kubernetes Project : Micro-Services on Kubeadm

Troubleshooting Period!

Introduction🧑‍🦯

Everything till now we have done in our local machine. we have gained knowledge on how to deploy pods and nodes, create master nodes and worker nodes, and create services and secrets using volumes and claims. Now this is the time I was awaiting⏳ (and you too), to do all these things outside the local system.

In this blog, we will be doing a hands-on project🧑‍💻 in which we will Set up and Deploy Microservices on Kubernetes Cluster using kubeadm and Expose them to Postman with Integration of Persistent Volumes and MongoDB and troubleshooting.

We will be using👇

  • python flask micro-services,

  • mongo db for the database,

  • kubeadm for cluster creation, and

  • Postman for accessing the application using persistent volume claims, we will be deploying an instance of mongo db and

a lot of troubleshooting!😵‍💫

Project: A simple task manager application. You can use the project or use our own. Your choice!

Github link: https://github.com/LondheShubham153/microservices-k8s

Setup Kubernetes Cluster using Kubeadm🏗

  1. First, you need an account in AWS to create instances

    Now, on the search bar, type instances and select EC2 and then select on Launch Instance button.

    Give the name at your convenience.

    • I am giving it kubernetes-master

    • Select the number of instances=2

    • Select the Ubuntu machine

    • Select t2.medium as an Instance type because in the free tier, only 1cpu is available and here we want 2 nodes set up, master and worker.

  • Now select a key-pair if you have already. If not then create new pair as I have done.

Now select on launch instance until it's running and passed the checks. And change the name of the 2nd instance as kubernetes-worker

  • Now it's time to connect these instances to your local machine.

  • Check the kubernetes-master box and then click on connect button and then copy the ssh key

  • Now open up your terminal and go inside the directory where you have downloaded that generated key-pair .pem file.

  • Run the command sudo <ssh-key> on both sides with their own key.

  • Now we have to install kubeadm, kubectl and kubelet in both the master & worker node. And before this, make sure you are inside that directory

  • In this Github, you will find all the commands you have to follow in order to install: https://github.com/RishikeshOps/Scripts/blob/main/k8sss.sh

    Open the terminal side by side for the master node and another for the worker node for convenience. And in the URL, paste the commands according to that.

  • Now in the master node, run:

  •                 sudo su
                    kubeadm init
    

    Then export it and then run the kubectl apply -f command.

    https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml

  • Now run the same command sudo su in the worker node and run:

  •                 sudo su
                    kubeadm reset pre-flight checks
    

    Now join the worker-node to the master-node by running the generated token in the master node:

    If you see the token carefully, it is listening to port:6443 so we have to add in the instance.

  • Click on the master-node then go to security and click on edit inbound rules.

    Now add the port to it

    Now see the worker node terminal. It has joined the cluster.

    Now you can check the nodes

Deploy the Taskmaster Micro-services🥸

  • Now clone the GitHub project which I have shared the link already above.

    Now you can the nodes and pods that are running.

    The left one is the master-node and the right is the worker-node. You can see running pods on both sides.

  • Now, there is only a pod running. Let's scale this up to three using the --scale command.

    Now the three pods are up and running.

    Let's deploy the service now. Check the taskmaster-svc.yml file.

    Now, run the kubectl apply command:

    Check the service created by you so that we can access our application.

    30007 is the port in which our application is running.

  • Now again, we have to add this port t our aws console master node instance.

    Now click on the worker-node and copy its IP address.

Exposes the Service to Postman🧑‍✈️📥

  • Now paste this URL into the health check cluster with port:30007 and send the requests.

    As you can see our application is running now.

  1. Integrate Persistent Volumes & Persistent Volume Clain
  • Now we will create persistent volume. It has a mongo-pv.yml file in it. We just have to do kubectl apply -f <file-name> command:

    Let's see the created volumes by using the get command:

    As you can see above, the volume is available for us but nobody has claimed it yet. So now we will create the persistent volume claim.

    Now again, run the same command to see the created volumes

    This time you can see, the storage is claimed now and bounded

Deploy Mongo DB🛗

  • Now let's see the mongo.yml file.

    We will deploy this file to create the deployment of mongo db

    We have created everything we want. Now let's see the running pods on both nodes.

Integrate Micro-Services🕵️

  • Let's create the service for the mongo.yml file. It has already been coded in mongo-svc.yml :

    Run the apply command to implement the above file. And get the command to see the IPs and Ports

    This application is a task manager in which we can also add more tasks to it and it must be running.

  • So let's see to run the same URL for the /tasks section.

    So basically, I don't know what just happened.

Troubleshooting🤕

Today's challenge is all about making a project available and the challenges we faced in doing so and coming over from it.

As we all are doing a 7-day Kubernetes challenge together, we know there are topics for daily to perform. And today we have to perform with AWS, kubeadm, Postman etc.

The problems I have faced doing this project are listed below:👇

  1. AWS Sign-up -

    • This is my first time doing hands-on in aws. So I don't have any account on it.

    • Today early morning I started with doing sign-up. The registration process takes time as it will demand credit/debit card credentials.

    • I submitted the credentials but for no reason, it was unable to take my card credentials. May be bank side issue I don't know. So I waited for a while and tried again after an hour and I signed up.

    • After signing up the Instances section is not showing, it's saying It may take up to 24 hours to start your account.

    • For a moment I thought today I will not make it happen. Then after some time, I tried again and then it worked.

    • So it took me almost 2hours to sign-up for aws.

  2. Correct Directory: When I was generating the keys while creating the instances. The first thing we need to do on entering the terminal is to go inside the directory where the .pem file was downloaded. And I forgot that. And doing sudo ssh in the root directory.

    Then I asked for help from one of the folk then I got my issue resolved. I changed my directory then everything start working.

  3. Network Connectivity - I was doing this whole thing with learning and doing alongside. And suddenly I got this error message:

    And without trying to resolve this, I did the whole procedure from creating instances to installing everything, did all the deployments again then continued further where I left off.

  4. Postman API - I have never worked on Postman so I don't even know the purpose of using it. It took me a lot of time to get started with this service. I watched several youtube videos to understand how it works. Because we need to create GET, PUT and POST method requests for the application to run.

  5. TimoutError - The last error where we stopped, I am still figuring out how to solve that for very long. And I will do that.

Take Aways from My Troubleshooting🎒

  1. If you are doing any challenge like me or preparing for it. Must sign-up early for an AWS account because not for everyone but it might take a day to start your account as it says. So better early than late.🤓

  2. Always follow the steps mentioned already for installation and recheck every step as it can cause you to do the whole process again. And that's very frustrating.😖

  3. A stable internet connection. I know it sounds very childish in a takeaway section, but trust me if you are not in a stable connection it will kill you. And I am dead now.🫠

  4. To do projects like this, you must know each and every aspect of it. You must learn firsts and then apply. It will give you a good understanding and the better results.

  5. Now, talking about the last timeouterror, I am solving the issue and will update this blog soon. Just holding this up for the sake of completing today's challeneg as it is the last day. So if you are reading this in the present tense then let's do it together✊ and comment on your solution, we can discuss it. And if you are reading this in the future then, Nothing. Everything is fine and updated.😄

My learnings from this challenge🧑‍🎓

  • I am learning Kubernetes for a while. But in my learning I was not doing it practically, only learning concepts and moving further without implementing anything🤐. And this challenge changed my way of learning completely. As daily I learned a new topic and implemented it immediately🤯.

  • I have never done this type of challenge before. It trained me how to push myself to learn new things daily♿. And I have never done that. So that's a big achievement for me!🤓

  • I learned architecture before but never get into depth but this time for the sake of writing blogs I deep dive into the architectures of Kubernetes.

  • I learned how to work with AWS and Postman API.

  • I learned how to create an instance and connect it to the local environment and many such things.

A Closing Note!📜

As this is the last of the 7-day series I have mixed feelings. I am relaxed but also quite unhappy because I am a procrastinator and this daily challenge has encouraged me to learn a new topic daily. And this was a big advantage of this challenge.

A message for you!✍️

Don't give up if you lack somewhere behind. If you didn't complete any one of the daily tasks, no worries! It's okk🙂, everyone has their own pace of learning. This 7-day series is not a race🐀 where you have to come first and win the prize.

If you didn't complete today's challenge it doesn't mean you are out of winning. A winner is the one who managed to learn daily in this series. I**f you have learned something new in these 7 days, you are the winner. Good Job!👏

I am thankful to Shubham Londhe sir for organizing this amazing 7-day Kubernetes challenge🔥 for the community. This week went amazing with super learnings. Hoping for more such challenges from you🙌.


Thank you all of you for being with me on this 7-day journey🖤.

Happy learnings!🧑‍💻