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.
For Prerequisites click here
Step 1 :
Create Two Servers: >> t2.micro - CI SERVER , >> t2.medium- Deployment Server .
Images:
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:
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:
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 :
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:
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:
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:
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:
Step 8: Expose the application
First We need to expose our deployment so use
kubectl expose deployment reddit-clone-deployment --type=NodePort
command.You can test your deployment using
curl -L http://{minikubeip}:31000. Port 31000
is defined in Service.ymlThen 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:
Final step
Navigate to your Chrome browser and enter http://{public-ip}:3000
Images:
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.