Deploying Reddit Copy on Kubernetes Cluster using Ingress.
Aashish R.
????System Engineer at Tata Consultancy Services | DevOps | Terraform | Kubernetes | Ansible | Jenkins | CI/CD | ??AWS | Docker | Grafana | GitHub | Linux |
Prerequisites:
?????????? EC2 (AMI- Ubuntu, Type- t2.medium)
?????????? Docker
?????????? Minikube
?????????? Kubectl
?
Follow below steps for install all necessary prerequisite:
#Docker Installation steps
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER && newgrp docker
# For Minikube & Kubectl
sudo install minikube-linux-amd64 /usr/local/bin/minikube
sudo snap install kubectl –classic
minikube start --driver=docker
?
Clone the source code:
git clone https://github.com/LondheShubham153/reddit-clone-k8s-ingress.git
Building Docker Image:
You can build docker image using below commands:
docker build -t <DockerHub_Username>/<Imagename> .
?
docker build -t trainwithshubham/reddit-clone .
or
docker build -t ashraw10/reddit-clone .
Push the image to Docker hub
First you have to login on Docker hub using below command
docker login ?
give username and password.
Write a Kubernetes Manifest File
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.
?
Let’s create a Deployment file for our Application
Using the following code for the Deployement.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: trainwithshubham/reddit-clone
ports:
- containerPort: 3000
Write 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
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.
Run following command:
kubectl apply -f deployment.yml
kubectl apply -f service.yml
?Check your deployment and services using below command:
kubectl get deployment -o wide
kubectl get services -o wide
Let's Configure Ingress
Ingress in Kubernetes:
Pods and services in Kubernetes have their own IP; however, it is normally not the interface you'd provide to the external internet. Though there is a service with node IP configured, the port in the node IP can't be duplicated among the services. It is cumbersome to decide which port to manage with which service. Furthermore, the node comes and goes, it wouldn't be clever to provide a static node IP to an external service. Ingress defines a set of rules that allows the inbound connection to access Kubernetes cluster services. It brings the traffic into the cluster at L7 and allocates and forwards a port on each VM to the service port.
Write ingress.yml file using below code:
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.yml using below commands:
Kubectl apply –f ingress.yml
Use below command to verify ingress is running correctly:
kubectl get ingress ingress-reddit-app
To check ingress status used below command:
Kubectl get ingress –o wide
Test Ingress:
Now It's time to test your ingress so use the?curl -L domain/test?command in the terminal.
Note: open the 3000 port in a security group of your Ec2 Instance
Used Ec2_ip to see the deployed application on browser using
EC2_ip:3000
You have successfully deployed the Reddit clone app using ingress on Kubeadm cluster.
Thank you all!
Technical Product Owner | SDLC | Platform Engineering | FinOps | Technical Architect | Django Rest Framework | Microservices | Product development | RnD
1 年Good work
Machine Learning & Data Science Professional | Driving Insights & Automation Excellence | TCS Solution Architect | Process Optimization & Innovation Expert | Corporate Trainer & Mentor
1 年Keep growing keep learning
Looking for Job Change | DevOps Engineer at Yash Technologies Pvt Ltd | AWS | AZURE x2 | Jenkins | Docker | Terraform | Linux | Kubernetes | Github
1 年Congrats Aashish R.
DevSecOps Consultant at KPMG | AWS Certified Solution Architect | Ex - TCS
1 年Great Work Aashish R.
Microsoft Certified Data Analyst | Power BI | DAX | SQL | Python | Linux | TCS Digital
1 年Congratulations on the first article Aashish