Skip to main content

Command Palette

Search for a command to run...

Deploying a Swiggy Clone Application

Updated
Deploying a Swiggy Clone Application
H

Enthusiastic about DevOps tools like Docker, Kubernetes, Maven, Nagios, Chef, and Ansible and currently learning and gaining experience by doing some hands-on projects on these tools. Also, started learning about AWS and GCP (Cloud Computing Platforms).

In this blog, I have explained the process of deploying a Swiggy clone application. We'll start by making the docker image and then finally deploy it to a cluster.

Key Points

  • Clone the Swiggy clone repository and install the required dependencies

  • Create a Docker file and build the Docker image for the application

  • Scan the Docker image through trivy to find any vulnerabilities

  • Push the Docker image to a Docker registry (e.g., Docker Hub)

  • Deploy the Docker container to a Kubernetes cluster

Dependencies

  1. Docker

     sudo apt install docker.io
     sudo usermod -aG docker $USER
     sudo chmod 777 /var/run/docker.sock
    
  2. Trivy

     sudo apt-get install wget apt-transport-https gnupg lsb-release
     wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
     echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
     sudo apt-get update
     sudo apt-get install trivy
    
  3. Kubectl and Kind Cluster

     sudo snap install kubectl --classic
     kubectl version --client
     curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
     chmod +x ./kind
     sudo mv ./kind /usr/local/bin/kind
     kind create cluster --config kind.yaml
    

Steps

  1. Clone the Repository

     git clone https://github.com/harshitsahu2311/Swiggy-Clone-Deployment.git
    
  2. Create a Docker File

    • Create a new file named Dockerfile in the project directory

        FROM node:20.18.0-slim
      
        WORKDIR /app
      
        COPY package*.json ./
      
        RUN npm install
      
        COPY . .
      
        RUN npm run build  # Build React app
      
        RUN npm install -g serve  # Install serve globally
      
        EXPOSE 3000
      
        CMD ["serve", "-s", "build"]
      
    • Add the necessary instructions to the Docker file to build the Docker image

  3. Build the Docker Image

    • Run to build the Docker image

        docker build -t swiggy .
      
    • The image will be tagged as swiggy

  4. Scan the Docker image through trivy

     trivy image swiggy
    

  5. Push the Docker Image to a Registry

    • Log in to your Docker registry account (e.g., Docker Hub) through docker login.

    • Tag the image with your registry username and repository name: docker tag swiggy harshitsahu2311/swiggy:latest

    • Push the image to the registry: docker push harshitsahu2311/swiggy:latest

    • Docker Hub Image link: Swiggy-Clone

  6. Run the Docker Container to check the application

     docker run  -d -p 3000:3000 harshitsahu2311/swiggy-clone
    

Deployment to Kubernetes Cluster

  1. Set up a Kubernetes Cluster

    • Ensure you have a Kubernetes cluster set up and running

    • Install the necessary tools (e.g., kubectl) to interact with the cluster

  2. Create a Kubernetes Deployment

    • Create a new Kubernetes deployment file (e.g., deploy.yaml) to define the application deployment.

    • Specify the Docker image, container configuration, and other deployment settings.

        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: swiggy-deployment
          labels:
            app: swiggy
        spec:
          replicas: 2
          selector:
            matchLabels:
              app: swiggy
          template:
            metadata:
              labels:
                app: swiggy
            spec:
              containers:
              - name: swiggy
                image: harshitsahu2311/swiggy-clone:latest
                ports:
                - containerPort: 3000
      
  3. Deploy the Application

    • Apply the deployment file to the Kubernetes cluster:

        kubectl apply -f deploy.yaml
      
    • Verify it through

        kubectl get deploy
        kubectl get pods
      
  4. Manage the Deployment

    • Use kubectl commands to monitor the deployment, scale the application, and perform other management tasks

    • Example commands:

      • kubectl get pods: View the running pods

      • kubectl logs pod-name: View the logs of a specific pod

      • kubectl scale deployment/swiggy --replicas=2: Scale the deployment to 2 replicas

By following these steps, you can successfully deploy the Swiggy clone application to a Kubernetes cluster, ensuring scalability and reliability.

  1. Expose and Test the Application

    To expose your deployment, run:

     kubectl expose deploy swiggy-deployment --type=NodePort
    
     kubectl port-forward svc/swiggy-deployment 3000:3000 --address 0.0.0.0 &
    

Congratulations!!! You have successfully deployed the application on Kind Cluster.

You can also access it through

kubectl apply -f service.yaml
kubectl get svc
kubectl port-forward svc/swiggy-svc 3000:80 --address 0.0.0.0 &

Key Concepts

  • Kubernetes Cluster: A group of nodes (control plane and worker nodes) that run containerized applications

  • Deployment: A Kubernetes resource that manages the lifecycle of a set of pods

  • Service: A Kubernetes resource that exposes an application to the network

  • Port Forwarding: A mechanism to access an application running in a cluster from the host machine

Table of Key Commands

CommandDescription
kind create clusterCreate a Kubernetes cluster using the kind
kubectl get nodesList the nodes in the Kubernetes cluster
kubectl apply -f deployment.yamlApply a deployment file to create an application
kubectl create deploymentCreate a deployment using the imperative approach
kubectl expose deploymentExpose a deployment as a service
kubectl port-forward service/myservice 8080:80Forward a service port to a host port

DevOps Projects

Part 9 of 18

A curated series of practical DevOps projects showcasing my journey from foundational concepts to advanced workflows, including CI/CD, container orchestration, IaC, and cloud solutions—highlighting real-world expertise and continuous learning.

Up next

Deployment of Login Page with DB

using Docker Compose