Skip to main content

Command Palette

Search for a command to run...

Reddit clone app with Kubernetes

Published
•2 min read•View as Markdown

Prerequisites to be installed:

EC2 ( AMI- Ubuntu, Type- t2.medium{for Deployment server}, t2.micro {for CI derver})

Docker

Minikube

kubectl

Step 1 Run these commands

For Docker Installation on CI server and Deployment server

sudo apt-get update sudo apt-get install docker.io -y sudo usermod -aG docker $USER && newgrp docker

For Minikube & Kubectl on Deployment server only

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

Step 2 Clone the source code to the CI server

git clone https://github.com/ManishNegi963/reddit-clone-k8s-ingress.git

image

Step 3 Make a container of Application using docker by writing a Dockerfile

FROM node:19-alpine3.15

WORKDIR /reddit-clone

COPY . /reddit-clone

RUN npm install

EXPOSE 3000

CMD ["npm","run","dev"]

image

Step 4 Building docker image from Dockerfile and tagging the image

docker build . -t mnmanish/reddit-clone

image

Step 5 Login to dockerHub and push image to dockerHub

docker login

image

docker push mnmanish/reddit-clone:latest

image

Step 6 Now, go to deployment server and write deployment file.

vim deployment.yml

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: mnmanish/reddit-clone ports: - containerPort: 3000

Step 7 Write service,yml file

vim service.yml

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

Step 8 Deploy the deployment.yml file and service.yml file.

kubectl apply -f deployment.yml

image

--

image

--

image

kubectl apply -f service.yml

image

--

image

Step 9 Expose the app

kubectl expose deployment reddit-clone-deployment --type NodePort

image

Step 10 Expose the app service

kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0 &

image

Step 11 Open port on Security group of Deployment server

image

--

image

--

Reddit clone app is deployed.

image

More from this blog

Untitled Publication

32 posts