Reddit is like a giant online bulletin board where people worldwide share news, stories, images, and discussions. It's where you can find communities talking about everything, from cute animals to serious world events. Users post content, and others can upvote or downvote it, determining what's popular and what's not. It's a hub for diverse interests and conversations.
Essentials
Before you start, make sure you have these tools installed on your computer
Docker
K8s cluster ( Running )
Kubeadm
Git
Forking and Cloning the Project
Fork this Repository.
Clone it to your system.
git clone https://github.com/LondheShubham153/reddit-clone-k8s-ingress.git
Throughout this project, I've utilized the AWS EC2 instance. If you're keen to learn about setting up your own AWS EC2 Instance, Click here for a beginner-friendly guide.
Keep in mind: This project is resource-intensive, so it's recommended to use at least a t2.medium instance type for a smooth experience.
Creating a Deployment Configuration
I'm assuming you're familiar with installing and running the K8s architecture using Kubeadm. If not, no problem. Click here for a beginner-friendly guide on setting up a K8s cluster using Kubeadm.
Once the K8s cluster is set up, we're all set to launch our Reddit application on the server. Our first step is to create a deployment for the application.
apiVersion: apps/v1
kind: Deployment
metadata:
name: reddit-clone-deployment
labels:
app: reddit-clone
namespace: reddit-clone-ns
spec:
replicas: 3
selector:
matchLabels:
app: reddit-clone
template:
metadata:
labels:
app: reddit-clone
spec:
containers:
- name: reddit-clone
image: iamamash/reddit-clone:latest
ports:
- containerPort: 3000
In Kubernetes, a deployment file is like a recipe that tells Kubernetes how to run and manage your application. It defines what your app should look like, how many copies should run, and what to do if something goes wrong. It's like giving instructions to set up and keep your app running smoothly on Kubernetes.
Exposing the Application
Now, to make our application reachable from the outside world, we'll need to expose it using a specific port. In Kubernetes, this is achieved by setting up a service configuration.
Kubernetes is all about configuration, a service file is a way to expose your application on a particular port so that it can be accessed from outside the cluster. It's like creating a gateway that allows external traffic to reach your application running inside the Kubernetes cluster.
apiVersion: v1
kind: Service
metadata:
name: reddit-clone-service
spec:
type: NodePort
selector:
app: reddit-clone
ports:
- port: 3000
targetPort: 3000
nodePort: 30007
Editing the Inbound Rules
Notice that we're making our application accessible through port 30007
. However, this port might not be included in the inbound rules of the worker node by default. To enable access, we should add this port to the inbound rules and choose the source type as Anywhere-IPV4. Click on Save rules.
Applying the Configurations
We're almost ready to deploy our app using K8s. We've made all the needed configuration files, and now it's time to put them into action. Just apply these files to the cluster, and K8s will take care of deploying our app.
Start by applying the deployment file to the cluster with the following command.
kubectl apply -f deployment.yaml
Next, apply the service file so you can access it through your web browser.
kubectl apply -f service.yaml
Last but not least
Access the application in your browser using the port 30007
. You'll see your application shining brightly. Keep in mind that the application might take a moment to load since it's a bit larger.
Here's the link to my๐ Reddit Clone Application.