Deployed a Reddit Clone on Kubernetes with Ingress Enabled (04) : Day - 49

Table of contents


Setup CI server:

  1. Launch an ec2 instance with Ubuntu- t2.micro AMI type

  2. Install Docker:

  3. Clone Reddit app source code:
    https://github.com/Namg04/reddit-clone-k8s-ingress.git

  4. Create a docker image from the Dockerfile

  5. docker build . -t reddit-clone-image:latest

  6. Image has been created : sudo docker images

  7. Push the Reddit image to the DockerHub. Log in to the DockerHub from CLI

  8. You can verify the image from DockerHub as well once the image has been pushed:


Setup Deployment server:

  1. Launch instance for Deployment server: Ubuntu AMI, t2.medium

  2. 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

  3. Create a project directory to write required manifest files

  4. Create namespace kubectl create namespace reddit-app

  5. Write Deployment manifest file

  6. Run the deployment file by using kubectl apply -f Deployment.yml -n reddit-app

  7. Write service.yml file

  8. Run the Service.yml file: kubectl apply -f Service.yml -n reddit-app

  9. Get the URL : minikube service reddit-clone-service -n reddit-app created --url

  10. Expose the App Deployment:
    kubectl expose deployment reddit-clone-deployment -n reddit-app --type=NodePort

  11. Expose the App Service:
    kubectl port-forward svc/reddit-clone-service -n reddit-app 3000:3000 --address 0.0.0.0

  12. Open 3000 port in the Deployment Server of the security group

  13. 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:

  1. Write ingress.yml file

  2. Enable minikube ingress: minikube addons enable ingress

  3. Check the Current settings of addons in Minikube: minikube addons list

  4. Run ingress file: kubectl apply -f ingress.yml -n reddit-app
    Check the created ingress file: kubectl get ingress

  5. 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!!!😊