๐Reddit Clone with Kubernetes Ingress
Deploying a Reddit Clone with Kubernetes Ingress involves several steps. Here's a detailed, step-by-step process to guide you through the deployment:

๐Flow of the Project

Step 1: Prerequisites
GitHub
2 EC2 instances with minimum t2.medium instance type.
Docker & DockerHub
Minikube - It is a lightweight version of Kubernetes that runs a single-node cluster on a local machine.
Kubectl - It is a command line tool that interacts with Kubernetes clusters.
Step 2: Installation in first Instance
- Install Docker in the First Instance (CI Server)
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER && newgrp docker
- After Installation, Clone the GitHub Repository in First Instance (CI Server)
git clone https://github.com/mandgepratik/reddit-clone-k8s-ingress.git

- Check, whether Repository clone or not
ls # To check Reddis Clone Repository
Step 3: Build Dockerfile
- Here is a Dockerfile,
FROM node:19-alpine3.15
WORKDIR /reddit-clone
COPY . /reddit-clone
RUN npm install
EXPOSE 3000
CMD ["npm","run","dev"]
- To build the Dockerfile, use Command:
docker build . -t andropython/reddit-clone #<DockerHub_Username>/<Imagename>
Step 4: Push the Image to DockerHub
After build, push this Docker Image to DockerHub so our Deployment file can pull this image & run the app in Kubernetes pods.
First login to your DockerHub account using Command i.e
docker loginand give your username & password.After Login Succeeded, Push your Docker Image to DockerHub using command:
docker push andropython/reddit-clone:latest #Here is a latest docker image name
Now, Go to your DockerHub account your image will be push in DockerHub:

Step 5: Now, Installation in Second Instance
Install Docker in the Second Instance (Deployment Server)
sudo apt-get update sudo apt-get install docker.io -y sudo usermod -aG docker $USER && newgrp dockerAfter Installing Docker, Install the Minikube in the Second Instance (Deployment Server)
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
Step 6: Deploy Reddit Clone Application
For Deploy the Docker Image, You should make one directory in that, you need to write Deployment.yml file:
apiVersion: apps/v1 kind: Deployment metadata: name: reddit-clone-deployment labels: app: reddit-clone spec: replicas: 2 # For Scaling, You can increase replicas as per your requirement selector: matchLabels: app: reddit-clone template: metadata: labels: app: reddit-clone spec: containers: - name: reddit-clone image: andropython/reddit-clone ports: - containerPort: 3000Now, Write Service.yml file.
apiVersion: v1 kind: Service metadata: name: reddit-clone-service labels: app: reddit-clone spec: type: NodePort #type of service ports: - port: 3000 targetPort: 3000 #App runs on 3000 port. nodePort: 31000 selector: app: reddit-cloneNow, use command to deploy the Deployment.yml and Service.yml file:
kubectl apply -f Deployment.yml #it configured the deployment kubectl apply -f Service.yml #it creates the servicesTo check, pods are ready or not use command:
kubectl get deployment
Step 7: Application works or not
To access your application, use command:
minikube service reddit-clone-service --url # you'll get URLTo run your application in local, use command:
curl -L above generated url #Paste here above url, your app will runs locally.
Step 8: Expose the Application
First we need to expose our deployment so, use command:
kubectl expose deployment reddit-clone-deployment --type=NodePort #Your service will get exposeNow, go to your Instance (Deployment Server), Open Security group->inbound rules->Create new inbound rule for 3000 port:

Now, you need to port forwarding to expose application:
kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 & # & - means your application runs in background
Step 9: Let's Configure Ingress
Ingress - In Kubernetes, an ingress is an API object that controls how internet traffic reaches services within a Kubernetes cluster. It consists of an ingress API object and an ingress controller, which acts as a reverse proxy and load balancer. The ingress controller receives configuration requests from the ingress and adjusts its configuration to fulfill the request.

To enable ingress in minikube, use command:
minikube addons enable ingress #You'll get ingress is enableNow, write ingress.yml file,
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: 3000Now, Apply ingress.yml using command:
kubectl apply -f ingress.yml #You'll get ingress is created.To check, app runs or not enter:
curl -L domain.com/test #Your app running locally

- You can also see the deployed application on YourIP:3000

๐Finally,You have successfully Deployed a Reddit Copy on Kubernetes with Ingress Enabled.
I believe this blog will be really helpful, giving you fresh perspectives and teaching you something new and interesting. ๐
๐ Enjoy learning!
๐Copyright ยฉ Pratik R. Mandge, 2024. All rights reserved.
This article and its content are protected by copyright law. Reproduction or distribution of this article without the author's permission is prohibited. For inquiries, please contactpratikmandge021@gmail.com
About the author
Hey there! ๐
I'm Pratik R. Mandge, a DevOps Engineer passionate about all things AWS DevOps Technology. Currently on a learning adventure, I'm here to share my journey and Blog's in the world of cloud and DevOps.
๐ ๏ธ My focus? Making sense of AWS services, improving CI/CD, and diving into infrastructure as code. Whether you're fellow interns or curious enthusiasts, let's grow together in the vibrant DevOps space.
๐ Connect with me for friendly chats, shared experiences, and learning moments. Here's to embracing the learning curve and thriving in the exciting world of AWS DevOps Technology!
Follow me on LinkedIn: https://www.linkedin.com/in/pratik-mandge363
Comments
Join the discussionTo check the pods commands are kubectl get pods
DevOps Projects for Resume Building
"Discover practical DevOps projects covering CI/CD, IaC, monitoring, and more. Gain hands-on experience and enhance your DevOps skills."




