Project: Deployment Of Redit Clone application using Kubernetes with Ingress and expose it to the world using Minikube as the cluster.

Project: Deployment Of Redit Clone application using Kubernetes with Ingress and expose it to the world using Minikube as the cluster.

·

2 min read

Required tools for this project-:

  • Docker

  • Minikube cluster ( Running )

  • kubectl

  • Git

    steps to execute this project-:

    Step 1: Clone this repository to your local machine: git clone https://github.com/LondheShubham153/reddit-clone-k8s-ingress.git

    Step 2: Navigate to the project directory: cd reddit-clone-k8s-ingress

    Step 3: Create a Dockerfile for redit-app.

      FROM node:19-alpine3.15
    
      WORKDIR /reddit-clone
    
      COPY . /reddit-clone
      RUN npm install
    
      EXPOSE 3000
      CMD ["npm","run","dev"]
    

    Step 4: Build the Docker image for the Reddit clone app: docker build -t reddit-clone-app

    Step 5: Push the docker container to the docker hub. Command to push the docker image is:

      login to dockerhub in local:
      docker login
      push the container to dockerhub:
      docker push achyut197/redit-clone:latest
    

    Step 6: Deploy the app to Kubernetes: kubectl apply -f deployment.yaml . 6

    deployment.yaml:

      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: achyut197/redit-clone
              ports:
              - containerPort: 3000
    

    Step 7: Access this app outside the cluster by creating a service.yaml .apply the service.yaml file by using kubectl command.

      # service.yaml-:
      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
    
  •     kubectl apply -f service.yaml
    

    Step 8: create URL link for redit app to access:

  •     minikube service redit-clone-service --url
        curl -L http://192.168.49.2:31000
    

    redit-clone app was deployed.

    Step 9: Enable Ingress by using Command: minikube addons enable ingress

    Step 10: Expose the app as a Kubernetes service: kubectl expose deployment reddit-deployment --type=NodePort --port=500

    Step 11: forward redit-clone service.

    Step 12: Create an Ingress resource: kubectl apply -f ingress.yaml

    ingress.yaml:

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

Step 13: Test Ingress by typing this command: curl http://domain.com/test

I have done this project successfully.

Did you find this article valuable?

Support Achyut Das by becoming a sponsor. Any amount is appreciated!