Setup CI server:
Launch an ec2 instance with Ubuntu- t2.micro AMI type
Install Docker:
Clone Reddit app source code:
https://github.com/Namg04/reddit-clone-k8s-ingress.git
Create a docker image from the Dockerfile
docker build . -t reddit-clone-image:latest
Image has been created :
sudo docker images
Push the Reddit image to the DockerHub. Log in to the DockerHub from CLI
You can verify the image from DockerHub as well once the image has been pushed:
Setup Deployment server:
Launch instance for Deployment server: Ubuntu AMI, t2.medium
Install Docker and Minikube + Kubectl
# For Docker Installation
sudo apt-get update sudo apt-get install
docker.io
-y sudo usermod -aG docker $USER && newgrp docker
# For Minikube & Kubectl
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
Create a project directory to write required manifest files
Create namespace
kubectl create namespace reddit-app
Write Deployment manifest file
Run the deployment file by using
kubectl apply -f Deployment.yml -n reddit-app
Write service.yml file
Run the Service.yml file:
kubectl apply -f Service.yml -n reddit-app
Get the URL :
minikube service reddit-clone-service -n reddit-app created --url
Expose the App Deployment:
kubectl expose deployment reddit-clone-deployment -n reddit-app --type=NodePort
Expose the App Service:
kubectl port-forward svc/reddit-clone-service -n reddit-app 3000:3000 --address 0.0.0.0
Open 3000 port in the Deployment Server of the security group
Access your Reddit app:
💥💥💥Boom💥💥💥
minikube addons enable ingress
Ingress:
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. This is shown in the following figure. We define a set of rules and post them as source type ingress to the API server. When the traffic comes in, the ingress controller will then fulfill and route the ingress by the ingress rules. As shown in the following figure, ingress is used to route external traffic to the Kubernetes endpoints by different URLs:
Write ingress.yml file
Enable minikube ingress:
minikube addons enable ingress
Check the Current settings of addons in Minikube:
minikube addons list
Run ingress file:
kubectl apply -f ingress.yml -n reddit-app
Check the created ingress file:kubectl get ingress
Test your ingress: curl -L domain.com/test
You have successfully Deployed a Reddit Copy on Kubernetes with Ingress Enabled.
"Thank you for reading my blog! Happy Learning!!!😊
Stay tuned for more DevOps articles and follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/namratakumari04/ for the latest updates and discussions.