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.
Key technologies used: Docker, Docker Hub, Kubernetes, Minikube, CI/CD, Containerization, Automation, Monitoring, Logging, Reddit Clone Application.
For Prerequisites click here
Images:
First step is to clone the source code you can do it using bellow command
git clone https://github.com/Romeshdg/reddit-clone-k8s-ingress.git
Images:
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:
Build a Docker Image
docker build -t <image-name> .
For pushing the image to DockerHub you will need to login to the DockerHub account first for that use below command
docker login
You will be prompted to enter your docker account username and password.
If you don't have the DockerHub account then click here
Once logged in to your DockerHub account Use 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 :
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:
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:
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:
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>
- 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 following command:
kubectl apply -f ingress.yml -n <name-space>
Images:
-
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.yml
-
Then We have to expose our app service kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 &
Now It's time to test your ingress so use the curl -L domain/test command in the terminal.
Images:
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.
Thank you!