Deploying a Swiggy Clone Application

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
Docker
sudo apt install docker.io sudo usermod -aG docker $USER sudo chmod 777 /var/run/docker.sockTrivy
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 trivyKubectl 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
Clone the Repository
git clone https://github.com/harshitsahu2311/Swiggy-Clone-Deployment.gitCreate a Docker File
Create a new file named
Dockerfilein the project directoryFROM 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
Build the Docker Image
Run to build the Docker image
docker build -t swiggy .The image will be tagged as
swiggy
Scan the Docker image through trivy
trivy image swiggy
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:latestPush the image to the registry:
docker push harshitsahu2311/swiggy:latest
Docker Hub Image link: Swiggy-Clone
Run the Docker Container to check the application
docker run -d -p 3000:3000 harshitsahu2311/swiggy-clone
Deployment to Kubernetes Cluster
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
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
Deploy the Application
Apply the deployment file to the Kubernetes cluster:
kubectl apply -f deploy.yamlVerify it through
kubectl get deploy kubectl get pods
Manage the Deployment
Use
kubectlcommands to monitor the deployment, scale the application, and perform other management tasksExample commands:
kubectl get pods: View the running podskubectl logs pod-name: View the logs of a specific podkubectl 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.
Expose and Test the Application
To expose your deployment, run:
kubectl expose deploy swiggy-deployment --type=NodePortkubectl 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
| Command | Description |
kind create cluster | Create a Kubernetes cluster using the kind |
kubectl get nodes | List the nodes in the Kubernetes cluster |
kubectl apply -f deployment.yaml | Apply a deployment file to create an application |
kubectl create deployment | Create a deployment using the imperative approach |
kubectl expose deployment | Expose a deployment as a service |
kubectl port-forward service/myservice 8080:80 | Forward a service port to a host port |





