Automating the Delivery of Highly Scalable Reddit Clone Application using CI/CD Pipeline with Docker, Docker Hub, and Kubernetes Minikube

Automating the Delivery of Highly Scalable Reddit Clone Application using CI/CD Pipeline with Docker, Docker Hub, and Kubernetes Minikube

Highlights of this project:

πŸš€ Automated a highly available Reddit Clone application.

πŸš€ Used Docker, DockerHub, and Kubernetes to streamline the deployment process.

πŸš€ Implemented continuous deployment for easy updates and scalability.

πŸš€ Used Kubernetes Ingress to link the application to the domain for continuous availability.

βœ” Please check out my GitHub for more information and the code related to this project!

β–Ά GitHub Link
πŸ”—Romeshdg/reddit-clone-k8s-ingress: This project demonstrates how to deploy a Reddit clone app on Kubernetes with Ingress and expose it to the world using Minikube as the cluster. (github.com)

πŸ‘‰Key technologies used: Docker, Docker Hub, Kubernetes, Minikube, CI/CD, Containerization, Automation, Monitoring, Logging, Reddit Clone Application.

1678264485910

For Prerequisites click here

Step 1 :

Create Two Servers: >> t2.micro - CI SERVER , >> t2.medium- Deployment Server .

Images:

Screenshot 2023-03-11 210626

Step 2: Clone the source code

The first step is to clone the source code you can do it using below command

git clone https://github.com/Romeshdg/reddit-clone-k8s-ingress.git

Images:

Screenshot 2023-03-11 191647

Screenshot 2023-03-11 191812

Screenshot 2023-03-11 191955

Screenshot 2023-03-11 192125

Step 3 : Containerize the Application using Docker

Write a Dockerfile as below

FROM node:19-alpine3.15

WORKDIR /reddit-clone

COPY . /reddit-clone

RUN npm install 

EXPOSE 3000

CMD ["npm","run","dev"]

Images:

Screenshot 2023-03-11 192310

Step 4 : Building Docker-Image

Build a Docker Image

docker build -t <image-name> .

Step 5: Push the image to DockerHub

For pushing the image to DockerHub you will need to login to the DockerHub account first for that use the below command

docker login

You will be prompted to enter your docker account username and password.

βœ” If you don't have a DockerHub account then click here

Once logged in to your DockerHub account Use the bellow command to push your build image to the DockerHub repository

docker tag <image-id> <docker-username>/<image-name:tag>

docker push <docker-username>/<image-name:tag>

Images :

Screenshot 2023-03-11 192955

Screenshot 2023-03-11 193010

Screenshot 2023-03-11 193606

Screenshot 2023-03-11 193949

Step 6: Writing a Kubernetes Manifest File

Now, You might be wondering what this manifest file in Kubernetes is. Don't worry, I'll tell you in brief.

When you are going to deploy to Kubernetes or create Kubernetes resources like a pod, replica-set, config map, secret, deployment, etc, you need to write a file called manifest that describes that object and its attributes either in yaml or json. Just like you do in the Ansible playbook.

Of course, you can create those objects by using just the command line, but the recommended way is to write a file so that you can version control it and use it in a repeatable way.

Images:

Screenshot 2023-03-11 194243

Screenshot 2023-03-11 194605

Screenshot 2023-03-11 194658

Screenshot 2023-03-11 194949

Screenshot 2023-03-11 195045

Screenshot 2023-03-11 195346

  • Writing a Deployment.yml file

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: snaket2628/reddit-clone
        ports:
        - containerPort: 3000

Images:

Screenshot 2023-03-11 195438

Screenshot 2023-03-11 195815

Screenshot 2023-03-11 195848

  • Writing a Service.yml file

apiVersion: v1
kind: Service
metadata:
  name: reddit-clone-service
  labels:
    app: reddit-clone
spec:
  type: NodePort
  ports:
  - port: 3000
    targetPort: 3000
    nodePort: 31000
  selector:
    app: reddit-clone

Images:

Screenshot 2023-03-11 200751

Step 7: Deploy the app to Kubernetes & Create a Service for it.

Now, we have a deployment file for our app and we have a running Kubernetes cluster, we can deploy the app to Kubernetes. To deploy the app you need to run following the command:

kubectl apply -f deployment.yaml -n <name-space>

Same for the service file

kubectl apply -f service.yaml -n <name-space>

Configuring the Ingress

  • Writing ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-reddit-app
spec:
  rules:
  - host: "domain.com"
    http:
      paths:
      - pathType: Prefix
        path: "/test"
        backend:
          service:
            name: reddit-clone-service
            port:
              number: 3000
  - host: "*.domain.com"
    http:
      paths:
      - pathType: Prefix
        path: "/test"
        backend:
          service:
            name: reddit-clone-service
            port:
              number: 3000

apply the ingress file with the following command:

kubectl apply -f ingress.yml -n <name-space>

Images:

Screenshot 2023-03-11 200751

Screenshot 2023-03-11 201005

Screenshot 2023-03-11 201301

Screenshot 2023-03-11 203346

Screenshot 2023-03-11 203937

Step 8: Expose the application

  1. First We need to expose our deployment so use kubectl expose deployment reddit-clone-deployment --type=NodePort command.

  2. You can test your deployment using curl -L http://{minikubeip}:31000. Port 31000 is defined in Service.yml

  3. Then We have to expose our app service kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 & Forwarding from 0.0.0.0:3000 -> 3000

Test Ingress

Now It's time to test your ingress so use the curl -L domain/test command in the terminal.

Images:

Screenshot 2023-03-11 204650

Final step

Navigate to your Chrome browser and enter http://{public-ip}:3000

Images:

Screenshot 2023-03-11 205530

Screenshot 2023-03-11 204008

Overall, this project demonstrates how DevOps practices can be used to enhance the user experience and ensure the continuous availability of web applications. By automating the deployment process and using tools like Docker, DockerHub, and Kubernetes, developers can focus on improving the application itself while leaving the deployment process to the machines.

πŸ“ Thanks for reading, and happy learning! :) ✌

✨Let's continue to learn and grow together.

follow me on LinkedIn for more updates and insights. Also, don't forget to like, share, and comment on this post to spread the word and help others in their Learning journey.

Did you find this article valuable?

Support Romesh Dharamgudi by becoming a sponsor. Any amount is appreciated!

Β