Assignment: Deployment of a Microservices Application on Kubernetes and Deployment of a Reddit Clone Application

Assignment: Deployment of a Microservices Application on Kubernetes and Deployment of a Reddit Clone Application

ยท

3 min read

๐Ÿ”ถ Task-1. Deployment of a Microservices Application on K8s

- Do Mongo Db Deployment

- Do Flask App Deployment

- Connect both using Service Discovery

Make 2 instances of t2.medium, master and worker node.
Use the following commands to both the master and worker server.

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 

# 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

Use the following command to master.

 sudo su
 kubeadm init

 # To start using your cluster, you need to run the following as a regular user:
   mkdir -p $HOME/.kube
   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   sudo chown $(id -u):$(id -g) $HOME/.kube/config

 # Alternatively, if you are the root user, you can run:
   export KUBECONFIG=/etc/kubernetes/admin.conf

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

 kubeadm token create --print-join-command

Run the below command on the worker node.
sudo su
sudo kubeadm reset pre-flight checks

To connect the worker node use the print join command token to the worker node server append with --v=5

To install and run the application on your Kubernetes cluster, follow these steps:

  1. Clone this repository to your local machine of the master.

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

  2. Navigate to the project root directory.

  3. Create a Kubernetes deployment and service by running the following command:

kubectl apply -f <yml files.yml


๐Ÿ”ถ Task-2. Deployment of a Reddit-Clone Application

- Do Deployment of the Reddit Clone app

- Write an ingress controller for the same to give a custom route

# First all update system and install Docker 
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER && newgrp docker

# To install Minikube & Kubectl
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube 

sudo snap install kubectl --classic
minikube start --driver=docker

Follow these steps to install and run the Reddit clone app on your machine:

  1. Clone this repository to your local machine: git clone https://github.com/Chandreshpatle28/reddit-clone-k8s-ingress.git

  2. Build the Docker image for the Reddit clone app: docker build -t chandreshpatle28/reddit-clone:latest .

Edit your deployment.yml file with your image.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: reddit-clone-deployment
  labels:
    app: reddit-clone
spec:
  replicas: 2
  selector:
    matchLabels:
      app: reddit-clone
  template:
    metadata:
      labels:
        app: reddit-clone
    spec:
      containers:
      - name: reddit-clone
        image: chandreshpatle28/reddit-clone:latest
        ports:
        - containerPort: 3000

Login to your Docker Hub by using your username and password and push your image to Docker Hub

docker push chandreshpatle28/reddit-clone:latest

Deploy the app to Kubernetes by using

kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl apply -f ingress.yml
#check pod services and deployment
kubectl get pods
kubectl get deployment
kubectl get services
#expose our deployment by using 
kubectl expose deployment reddit-clone-deployment --type=NodePort
#expose our app service 
kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0

Check the application on the server with your ec2 server IP http://54.208.200.248:3000/



Happy Learning :)

Stay in the loop with my latest insights and articles on cloud โ˜๏ธ and DevOps โ™พ๏ธ by following me on Hashnode, LinkedIn (https://www.linkedin.com/in/chandreshpatle28/), and GitHub (https://github.com/Chandreshpatle28).

Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.

#Git #Linux Devops #Devopscommunity #90daysofdevopschallenge #python #docker #Jenkins #Kubernetes

Did you find this article valuable?

Support Chandresh Patle's Blog by becoming a sponsor. Any amount is appreciated!

ย