Deploying a Reddit Clone with Ingress in Kubernetes utilizing Minikube🚀
Problem Statement: Deployment of a Reddit-Clone Application🌐
- Do Deployment of the Redit Clone app
- Write an ingress controller for the same to give a custom route
💡Task 1: Deploy a Reddit Clone App
For the second challenge, you'll dive into the world of web applications by deploying a Reddit Clone app. This is an excellent opportunity to apply your Kubernetes knowledge to real-world scenarios.
You'll need to:
Create Kubernetes resources (deployments, services, etc.) for the Reddit Clone application.
Ensure that the app is up and running on your cluster.
🔹 Step 1: Install minikube on AWS EC2 instance
Follow the below blog for minikube installation: https://ayushi1503.hashnode.dev/getting-started-installing-minikube-and-creating-your-first-kubernetes-pod
🔹 Step 2: Cloning the repository of the project
Inside the projects
directory clone the GitHub repository:
https://github.com/Vasishtha15/reddit-clone-k8s-ingress.git
git clone https://github.com/Vasishtha15/reddit-clone-k8s-ingress.git
🔹Step 3: Navigate to project directory and create a namespace named reddit
🔹Step 4: Apply the deployment file
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: reddit-clone-deployment
namespace: reddit
labels:
app: reddit-clone
spec:
replicas: 2
selector:
matchLabels:
app: reddit-clone
template:
metadata:
namespace: reddit
labels:
app: reddit-clone
spec:
containers:
- name: reddit-clone
image: rohanrustagi18/redditclone
ports:
- containerPort: 3000
kubectl apply -f deployment.yml
Deployment is created.
Now, Verify the the deployment-
Verify the pod status-
🔹Step 5: Apply the service file and verify it.
service.yml
:
apiVersion: v1
# Indicates this as a service
kind: Service
metadata:
# Service name
name: reddit-clone-service
namespace: reddit
spec:
selector:
# Selector for Pods
app: reddit-clone
ports:
# Port Map
- port: 3000
targetPort: 3000
protocol: TCP
type: LoadBalancer
kubectl apply -f service.yml
💡Task 2: Write an Ingress Controller
To make the Reddit Clone accessible from the outside world, you'll need to configure an ingress controller. This allows you to provide a custom route to your application.
You'll need to:
Set up an ingress controller.
Define rules and routes to access your Reddit Clone app.
Test the custom routes to ensure they work as expected.
ingress.yml
:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-reddit-app
namespace: reddit
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
🔹 Step 1: Apply the ingress file and verify it.
kubectl apply -f ingress.yml
🔹 Step 2:Exposing the deployment:
kubectl expose deployment reddit-clone-deployment -n reddit --type=NodePort
🔹 Step 3:Exposing the service:
kubectl port-forward svc/reddit-clone-service -n reddit 3000:3000 --address 0.0.0.0
🔹 Step 4: Add port 3000
to the security group of your instance.
🔹 Step 5: Test the Application
Go to your browser and access the application at ec2_ip:3000
:
🌟Conclusion:
In this problem statement, we have further expanded our Kubernetes prowess. We orchestrated the deployment of a multi-component application, comprising frontend, backend, and database services. To enhance accessibility and user experience, we ventured into the realm of Ingress controllers. Crafting custom routes and directing traffic with precision, we optimized the accessibility of our Reddit Clone application.
Thank you for joining me on this Kubernetes expedition. Stay tuned for more exciting challenges and discoveries in the world of DevOps. 🚀
Subscribe to my newsletter
Read articles from Ayushi Vasishtha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ayushi Vasishtha
Ayushi Vasishtha
👩💻 Hey there! I'm a DevOps engineer and a tech enthusiast with a passion for sharing knowledge and experiences in the ever-evolving world of software development and infrastructure. As a tech blogger, I love exploring the latest trends and best practices in DevOps, automation, cloud technologies, and continuous integration/delivery. Join me on my blog as I delve into real-world scenarios, offer practical tips, and unravel the complexities of creating seamless software pipelines. Let's build a strong community of tech enthusiasts together and embrace the transformative power of DevOps!