Deploying a Microservice Application

Deploying a Microservice Application

Getting Started:

Installation of Kubeadm on machine

Both the Master and Worker Nodes

Run the following commands on the master and worker nodes to prepare them for Kubeadm.

# using 'sudo su' is not a good practice.
sudo apt update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo apt install docker.io -y

sudo systemctl enable --now docker # enable and start in single command.

# Adding GPG keys.
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg

# Add the repository to the sourcelist.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt update 
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y

Master Node

  1. Initialize the Kubernetes master node.

     sudo kubeadm init
    

    image

    After successfully running, your Kubernetes control plane will be initialized successfully.

    image

  2. Set up local kubeconfig (both for the root user and the average user):

     mkdir -p $HOME/.kube
     sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
     sudo chown $(id -u):$(id -g) $HOME/.kube/config
    

    image

  3. Apply Weave Network:

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

    image

  4. Generate a token for worker nodes to join:

     sudo kubeadm token create --print-join-command
    

    image

  5. Expose port 6443 in the Security group for the Worker to connect to the master node.

image

Deploying Microservice application on Kubernetes

We will clone the repo of one Flask Application to Deploy

git clone https://github.com/LondheShubham153/microservices-k8s.git

Then we will move to That directory, where the manifest file will be present.

cd microservices-k8s/flask-api/k8s/

First, we will start with the Mongo deployment installation

 kubectl apply -f mongo-pv

 kubectl apply -f mongo-pvc.yml

kubectl apply -f mongo.yml

Then we Install our main application deployment file

kubectl apply -f taskmaster.yml

kubectl apply -f taskmaster-svc.yml

We list the number of pods we have created

 kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
mongo-6879558ffc-mr4rz        1/1     Running   0          7m32s
taskmaster-74fd98cbd6-d8dfk   1/1     Running   0          3m12s

Then will Check using the Curl command

curl http://127.0.0.1:30007

The results show this:

{"message":"Welcome to Tasks app! I am running inside taskmaster-74fd98cbd6-d8dfk pod!"}

If you want to add more tasks, use this command:

{"message":"Welcome to Tasks app! I am running inside taskmaster-74fd98cbd6-d8dfk pod!"}

Thank you for reading my blog. Subscribe to my newsletter for the upcoming Wonderful Blogs.