diff --git a/Automations/updateBackend.sh b/Automations/updateBackend.sh new file mode 100755 index 000000000..5a797957d --- /dev/null +++ b/Automations/updateBackend.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Initializing variables +file_to_find="../backend/.env.docker" +alreadyUpdate=$(sed -n "4p" ../backend/.env.docker) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# Use curl to fetch the public IPv4 address from the metadata service +ipv4_address=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) + +echo -e " ${GREEN}System Public Ipv4 address ${NC} : ${ipv4_address}" + +if [[ "${alreadyUpdate}" == "FRONTEND_URL=\"http://${ipv4_address}:5173\"" ]] +then + echo -e "${YELLOW}${file_to_find} file is already updated to the current host's Ipv4 ${NC}" + exit -1; +else + if [ -f ${file_to_find} ] + then + echo -e "${GREEN}${file_to_find}${NC} found.." + echo -e "${YELLOW}Configuring env variables in ${NC} ${file_to_find}" + sleep 7s; + sed -i -e "s|FRONTEND_URL.*|FRONTEND_URL=\"http://${ipv4_address}:5173\"|g" ${file_to_find} + echo -e "${GREEN}env variables configured..${NC}" + else + echo -e "${RED}ERROR : File not found..${NC}" + fi +fi diff --git a/Automations/updateFrontend.sh b/Automations/updateFrontend.sh new file mode 100755 index 000000000..f66464893 --- /dev/null +++ b/Automations/updateFrontend.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Initializing variables +file_to_find="../frontend/.env.docker" +alreadyUpdate=$(cat ../frontend/.env.docker) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# Use curl to fetch the public IPv4 address from the metadata service +ipv4_address=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4) + +echo -e " ${GREEN}System Public Ipv4 address ${NC} : ${ipv4_address}" + +if [[ "${alreadyUpdate}" == "VITE_API_PATH=\"http://${ipv4_address}:31100\"" ]] +then + echo -e "${YELLOW}${file_to_find} file is already updated to the current host's Ipv4 ${NC}" + exit -1; +else + if [ -f ${file_to_find} ] + then + echo -e "${GREEN}${file_to_find}${NC} found.." + echo -e "${YELLOW}Configuring env variables in ${NC} ${file_to_find}" + sleep 7s; + sed -i -e "s|VITE_API_PATH.*|VITE_API_PATH=\"http://${ipv4_address}:31100\"|g" ${file_to_find} + echo -e "${GREEN}env variables configured..${NC}" + else + echo -e "${RED}ERROR : File not found..${NC}" + fi +fi diff --git a/Automations/updatebackendnew.sh b/Automations/updatebackendnew.sh new file mode 100644 index 000000000..89afec2cb --- /dev/null +++ b/Automations/updatebackendnew.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Set the Instance ID and path to the .env file +INSTANCE_ID="i-0c7c9d3d4e8c3a012" + +# Retrieve the public IP address of the specified EC2 instance +ipv4_address=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PublicIpAddress' --output text) + +# Initializing variables +file_to_find="../backend/.env.docker" +alreadyUpdate=$(sed -n "4p" ../backend/.env.docker) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +# Use curl to fetch the public IPv4 address from the metadata service + +echo -e " ${GREEN}System Public Ipv4 address ${NC} : ${ipv4_address}" + +if [[ "${alreadyUpdate}" == "FRONTEND_URL=\"http://${ipv4_address}:5173\"" ]] +then + echo -e "${YELLOW}${file_to_find} file is already updated to the current host's Ipv4 ${NC}" + exit -1; +else + if [ -f ${file_to_find} ] + then + echo -e "${GREEN}${file_to_find}${NC} found.." + echo -e "${YELLOW}Configuring env variables in ${NC} ${file_to_find}" + sleep 7s; + sed -i -e "s|FRONTEND_URL.*|FRONTEND_URL=\"http://${ipv4_address}:5173\"|g" ${file_to_find} + echo -e "${GREEN}env variables configured..${NC}" + else + echo -e "${RED}ERROR : File not found..${NC}" + fi +fi diff --git a/Automations/updatefrontendnew.sh b/Automations/updatefrontendnew.sh new file mode 100644 index 000000000..5c664fe9b --- /dev/null +++ b/Automations/updatefrontendnew.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Set the Instance ID and path to the .env file +INSTANCE_ID="i-0c7c9d3d4e8c3a012" + +# Retrieve the public IP address of the specified EC2 instance +ipv4_address=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PublicIpAddress' --output text) + +# Initializing variables +file_to_find="../frontend/.env.docker" +alreadyUpdate=$(cat ../frontend/.env.docker) +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +echo -e " ${GREEN}System Public Ipv4 address ${NC} : ${ipv4_address}" + +if [[ "${alreadyUpdate}" == "VITE_API_PATH=\"http://${ipv4_address}:31100\"" ]] +then + echo -e "${YELLOW}${file_to_find} file is already updated to the current host's Ipv4 ${NC}" + exit -1; +else + if [ -f ${file_to_find} ] + then + echo -e "${GREEN}${file_to_find}${NC} found.." + echo -e "${YELLOW}Configuring env variables in ${NC} ${file_to_find}" + sleep 7s; + sed -i -e "s|VITE_API_PATH.*|VITE_API_PATH=\"http://${ipv4_address}:31100\"|g" ${file_to_find} + echo -e "${GREEN}env variables configured..${NC}" + else + echo -e "${RED}ERROR : File not found..${NC}" + fi +fi diff --git a/GitOps/Jenkinsfile b/GitOps/Jenkinsfile new file mode 100644 index 000000000..63d11651d --- /dev/null +++ b/GitOps/Jenkinsfile @@ -0,0 +1,78 @@ +@Library('Shared') _ +pipeline { + agent {label 'Node'} + + parameters { + string(name: 'FRONTEND_DOCKER_TAG', defaultValue: '', description: 'Frontend Docker tag of the image built by the CI job') + string(name: 'BACKEND_DOCKER_TAG', defaultValue: '', description: 'Backend Docker tag of the image built by the CI job') + } + + stages { + stage("Workspace cleanup"){ + steps{ + script{ + cleanWs() + } + } + } + + stage('Git: Code Checkout') { + steps { + script{ + code_checkout("https://github.com/DevMadhup/wanderlust.git","devops") + } + } + } + + stage('Verify: Docker Image Tags') { + steps { + script{ + echo "FRONTEND_DOCKER_TAG: ${params.FRONTEND_DOCKER_TAG}" + echo "BACKEND_DOCKER_TAG: ${params.BACKEND_DOCKER_TAG}" + } + } + } + + + stage("Update: Kubernetes manifests"){ + steps{ + script{ + dir('kubernetes'){ + sh """ + sed -i -e 's/backend-wanderlust.*/backend-wanderlust:${params.BACKEND_DOCKER_TAG}/g' backend.yaml + """ + } + + dir('kubernetes'){ + sh """ + sed -i -e 's/frontend-wanderlust.*/frontend-wanderlust:${params.FRONTEND_DOCKER_TAG}/g' frontend.yaml + """ + } + + } + } + } + + stage("Git: Code update and push to GitHub"){ + steps{ + script{ + withCredentials([gitUsernamePassword(credentialsId: 'Github-cred', gitToolName: 'Default')]) { + sh ''' + echo "Checking repository status: " + git status + + echo "Adding changes to git: " + git add . + + echo "Commiting changes: " + git commit -m "Updated environment variables" + + echo "Pushing changes to github: " + git push https://github.com/DevMadhup/wanderlust.git devops + ''' + } + } + } + } + } +} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..6f97484e8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,119 @@ +@Library('Shared') _ +pipeline { + agent any + + environment{ + SONAR_HOME = tool "Sonar" + } + stages { + + stage("Workspace cleanup"){ + steps{ + script{ + cleanWs() + } + } + } + + stage('Git: Code Checkout') { + steps { + script{ + code_checkout("https://github.com/DevMadhup/wanderlust.git","devops") + } + } + } + + stage("OWASP: Dependency check"){ + steps{ + script{ + owasp_dependency() + } + } + post{ + success{ + archiveArtifacts artifacts: '**/dependency-check-report.xml', followSymlinks: false, onlyIfSuccessful: true + } + } + } + + stage("Trivy: Filesystem scan"){ + steps{ + script{ + trivy_scan() + } + } + } + + stage("SonarQube: Code Analysis"){ + steps{ + script{ + sonarqube_analysis("Sonar","wanderlust","wanderlust") + } + } + } + + stage("SonarQube: Code Quality Gates"){ + steps{ + script{ + sonarqube_code_quality() + } + } + } + + stage('Exporting environment variables') { + parallel{ + stage("Backend env setup"){ + steps { + script{ + dir("Automations"){ + sh "bash updateBackend.sh" + } + } + } + } + + stage("Frontend env setup"){ + steps { + script{ + dir("Automations"){ + sh "bash updateFrontend.sh" + } + } + } + } + } + } + + stage("Docker: Build Images"){ + steps{ + script{ + dir('backend'){ + docker_build("backend-wanderlust","test-image-donot-use","madhupdevops") + } + + dir('frontend'){ + docker_build("frontend-wanderlust","test-image-donot-use","madhupdevops") + } + } + } + } + + stage("Docker: Push to DockerHub"){ + steps{ + script{ + docker_push("backend-wanderlust","test-image-donot-use","madhupdevops") + docker_push("frontend-wanderlust","test-image-donot-use","madhupdevops") + } + } + } + } + + post{ + success{ + build job: "Wanderlust-CD", parameters: [ + string(name: 'FRONTEND_DOCKER_TAG', value: "test-image-donot-use"), + string(name: 'BACKEND_DOCKER_TAG', value: "test-image-donot-use") + ] + } + } +} diff --git a/README.md b/README.md index c064b393f..cc384cfa1 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,33 @@ _I'd love for you to make the most of this project - it's all about learning, he npm run dev ``` +### Setting up with Docker + +1. **Ensure Docker and Docker Compose are Installed** + +2. **Clone the Repository** + + ``` bash + + git clone https://github.com/{your-username}/wanderlust.git + ``` +3. **Navigate to the Project Directory** + + ```bash + + cd wanderlust + + ``` +4. **Update Environment Variables** - If you anticipate the IP address of the instance might change, update the `.env.sample` file with the new IP address. + +5. **Run Docker Compose** + + ```bash + + docker-compose up + ``` + This command will build the Docker images and start the containers for the backend and frontend, enabling you to access the Wanderlust application. + ## 🌟 Ready to Contribute? Kindly go through [CONTRIBUTING.md](https://github.com/krishnaacharyaa/wanderlust/blob/main/.github/CONTRIBUTING.md) to understand everything from setup to contributing guidelines. diff --git a/backend/.env.docker b/backend/.env.docker new file mode 100644 index 000000000..beb3d33c0 --- /dev/null +++ b/backend/.env.docker @@ -0,0 +1,10 @@ +MONGODB_URI="mongodb://mongo-service/wanderlust" +REDIS_URL="redis://redis-service:6379" +PORT=8080 +FRONTEND_URL="http://13.52.243.88:5173" +ACCESS_COOKIE_MAXAGE=120000 +ACCESS_TOKEN_EXPIRES_IN='120s' +REFRESH_COOKIE_MAXAGE=120000 +REFRESH_TOKEN_EXPIRES_IN='120s' +JWT_SECRET=70dd8b38486eee723ce2505f6db06f1ee503fde5eb06fc04687191a0ed665f3f98776902d2c89f6b993b1c579a87fedaf584c693a106f7cbf16e8b4e67e9d6df +NODE_ENV=Development diff --git a/backend/.env.sample b/backend/.env.sample index 858cea92a..d351fae8a 100644 --- a/backend/.env.sample +++ b/backend/.env.sample @@ -1,2 +1,2 @@ MONGODB_URI="mongodb://127.0.0.1/wanderlust" -REDIS_URL="127.0.0.1:6379" \ No newline at end of file +REDIS_URL="127.0.0.1:6379" diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 000000000..1776484b4 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,31 @@ +# Stage 1 +FROM node:21 AS backend-builder + +# setup the working dir +WORKDIR /app + +# code +COPY . . + +# packages install +RUN npm i + +# tests +RUN npm run test + +# Stage 2 +FROM node:21-slim + +# setup the working dir +WORKDIR /app + +# copy the above stage as compressed +COPY --from=backend-builder /app . + +COPY .env.docker .env + +# Port +EXPOSE 8080 + +# App +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..50b6e9709 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: "3.8" +services: + mongodb: + container_name: mongo + image: mongo:latest + volumes: + - ./backend/data:/data + ports: + - "27017:27017" + + backend: + container_name: backend + build: ./backend + env_file: + - ./backend/.env.docker + ports: + - "5000:5000" + depends_on: + - mongodb + + frontend: + container_name: frontend + build: ./frontend + env_file: + - ./frontend/.env.docker + ports: + - "5173:5173" + + redis: + container_name: redis + restart: unless-stopped + image: redis:7.0.5-alpine + expose: + - 6379 + depends_on: + - mongodb + +volumes: + data: diff --git a/frontend/.env.docker b/frontend/.env.docker new file mode 100644 index 000000000..ca9b94f82 --- /dev/null +++ b/frontend/.env.docker @@ -0,0 +1 @@ +VITE_API_PATH="http://13.52.243.88:31100" diff --git a/frontend/.env.sample b/frontend/.env.sample index 4a0ca5c61..1e8ba194f 100644 --- a/frontend/.env.sample +++ b/frontend/.env.sample @@ -1 +1 @@ -VITE_API_PATH="http://localhost:5000" \ No newline at end of file +VITE_API_PATH="http://localhost:5000" diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 000000000..aa9591df3 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,35 @@ +# ------------------- Stage 1: Build Stage ------------------------------ +FROM node:21 AS frontend-builder + +# Set the working directory to /app +WORKDIR /app + +# Copy the package.json and package-lock.json for dependency installation +COPY package*.json ./ + +# Install dependencies +RUN npm install + +Run npm run test + +# Copy the rest of the application code +COPY . . + +# ------------------- Stage 2: Final Stage ------------------------------ +FROM node:21-slim + +# Set the working directory to /app +WORKDIR /app + +# Copy built assets and dependencies from frontend-builder stage +COPY --from=frontend-builder /app . + +# Copy the .env.sample file to .env.local +COPY .env.docker .env.local + +# Expose port 5173 for the Node.js application +EXPOSE 5173 + +# Define the default command to run the application in development mode +CMD ["npm", "run", "dev", "--", "--host"] + diff --git a/kubernetes/README.md b/kubernetes/README.md new file mode 100644 index 000000000..414b5c24d --- /dev/null +++ b/kubernetes/README.md @@ -0,0 +1,192 @@ +# Wanderlust Deployment on Kubernetes + +### In this project, we will learn about how to deploy wanderlust application on Kubernetes. + +### Pre-requisites to implement this project: +- Create 2 AWS EC2 instance (Ubuntu) with instance type t2.medium and root volume 29GB. +- Setup Kubeadm + +# +## Steps for Kubernetes deployment: + +1) Become root user : +```bash +sudo su +``` + +# +2) Clone code from remote repository (GitHub) : +```bash +git clone -b devops https://github.com/DevMadhup/wanderlust.git +``` + +# +3) Verify nodes are in ready state or not : +```bash +kubectl get nodes +``` +![Alt text](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/nodes.png) + +# +4) Create kubernetes namespace : +```bash +kubectl create namespace wanderlust +``` +![Namespace](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/namespace%20create.png) + +# +5) Update kubernetes config context : +```bash +kubectl config set-context --current --namespace wanderlust +``` +![Update context](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/context%20wanderlust.png) + +# +6) Enable DNS resolution on kubernetes cluster : + +- Check coredns pod in kube-system namespace and you will find Both coredns pods are running on master node + +```bash +kubectl get pods -n kube-system -o wide | grep -i core +``` +![Alt text](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/get-coredns.png) + +- Above step will run coredns pod on worker node as well for DNS resolution + +```bash +kubectl edit deploy coredns -n kube-system -o yaml +``` + Make replica count from 2 to 4 + +![replica 4](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/edit-coredns.png) + +# +7) Navigate to frontend directory : +```bash +cd frontend +``` + +# +8) Edit .env.docker file and change the public IP Address with your worker node public IP : +```bash +vi .env.docker +``` +![IP](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/frontend.env.docker.png) + +# +9) Build frontend docker image : +```bash +docker build -t madhupdevops/frontend-wanderlust:v2.1.8 . +``` +![Dockerfile frontend](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/docker%20frontend%20build.png) + +# +10) Navigate to backend directory : +```bash +cd ../backend/ +``` + +# +11) Open .env.docker file and edit below variables : + + - MONGODB_URI: \ + - REDIS_URL: \ + - FRONTEND_URL: \ + +> Note: To get service names, check mongodb.yaml, redis.yaml + +![Backend env file](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/backend.env.docker.png) + +# +12) Build backend docker image : +```bash +docker build -t madhupdevops/backend-wanderlust:v2.1.8 . +``` +![Backend dockerfile](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/docker%20backend%20build.png) + +# +13) Check docker images: +```bash +docker images +``` +![docker images](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/docker%20images.png) + +# +14) Login to DockerHub and push image to DockerHub +```bash +docker login +``` +![docker login](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/docker%20login.png) + +```bash +docker push madhupdevops/frontend-wanderlust:v2.1.8 +docker push madhupdevops/backend-wanderlust:v2.1.8 +``` + +# +15) Once, Image is pushed to DockerHub, navigate to kubernetes directory +```bash +cd ../kubernetes +``` + +# +16) Apply manifests file the below order: + + - Create persistent volume : + ```bash + kubectl apply -f persistentVolume.yaml + ``` + ![Peristent volume](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/pv.png) + + - Create persistent volume Claim : + ```bash + kubectl apply -f persistentVolumeClaim.yaml + ``` + ![Peristent volume Claim](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/pvc.png) + + - Create MongoDB deployment and service : + ```bash + kubectl apply -f mongodb.yaml + ``` + ![MongoDb](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/mongo.png) + + - Create Redis deployment and service : + > Note: Wait for 3-4 mins to get mongodb, redis pods and service should be up, otherwise backend-service will not connect. + ```bash + kubectl apply -f redis.yaml + ``` + ![Redis](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/redis.png) + + - Create Backend deployment and service : + ```bash + kubectl apply -f backend.yaml + ``` + ![Backend](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/backend.png) + + - Create Frontend deployment and service : + ```bash + kubectl apply -f frontend.yaml + ``` + ![Frontend](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/frontend.png) + +# +17) Check all deployments and services : +```bash +kubectl get all +``` +![all deployments and services](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/all-deps.png) + +18) Check logs for all the pods : +> Note: This is mandatory to ensure all pods and services are connected or not, if not then recreate deployments +```bash +kubectl logs +``` + +20) Navigate to chrome and access your application at 31000 port : +```bash +http://:31000/ +``` +![App](https://github.com/DevMadhup/wanderlust/blob/devops/kubernetes/assets/app.png) + +# + diff --git a/kubernetes/assets/README.md b/kubernetes/assets/README.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/kubernetes/assets/README.md @@ -0,0 +1 @@ + diff --git a/kubernetes/assets/all-deps.png b/kubernetes/assets/all-deps.png new file mode 100644 index 000000000..29940eaff Binary files /dev/null and b/kubernetes/assets/all-deps.png differ diff --git a/kubernetes/assets/app.png b/kubernetes/assets/app.png new file mode 100644 index 000000000..fe7b2890b Binary files /dev/null and b/kubernetes/assets/app.png differ diff --git a/kubernetes/assets/backend.env.docker.png b/kubernetes/assets/backend.env.docker.png new file mode 100644 index 000000000..fbb051feb Binary files /dev/null and b/kubernetes/assets/backend.env.docker.png differ diff --git a/kubernetes/assets/backend.png b/kubernetes/assets/backend.png new file mode 100644 index 000000000..37d30fdf8 Binary files /dev/null and b/kubernetes/assets/backend.png differ diff --git a/kubernetes/assets/context wanderlust.png b/kubernetes/assets/context wanderlust.png new file mode 100644 index 000000000..89a4a024d Binary files /dev/null and b/kubernetes/assets/context wanderlust.png differ diff --git a/kubernetes/assets/docker backend build.png b/kubernetes/assets/docker backend build.png new file mode 100644 index 000000000..b940d4ebb Binary files /dev/null and b/kubernetes/assets/docker backend build.png differ diff --git a/kubernetes/assets/docker frontend build.png b/kubernetes/assets/docker frontend build.png new file mode 100644 index 000000000..d9d4157e1 Binary files /dev/null and b/kubernetes/assets/docker frontend build.png differ diff --git a/kubernetes/assets/docker images.png b/kubernetes/assets/docker images.png new file mode 100644 index 000000000..6c76001d3 Binary files /dev/null and b/kubernetes/assets/docker images.png differ diff --git a/kubernetes/assets/docker login.png b/kubernetes/assets/docker login.png new file mode 100644 index 000000000..e54cd7923 Binary files /dev/null and b/kubernetes/assets/docker login.png differ diff --git a/kubernetes/assets/edit-coredns.png b/kubernetes/assets/edit-coredns.png new file mode 100644 index 000000000..96fd1cfeb Binary files /dev/null and b/kubernetes/assets/edit-coredns.png differ diff --git a/kubernetes/assets/frontend.env.docker.png b/kubernetes/assets/frontend.env.docker.png new file mode 100644 index 000000000..591ede862 Binary files /dev/null and b/kubernetes/assets/frontend.env.docker.png differ diff --git a/kubernetes/assets/frontend.png b/kubernetes/assets/frontend.png new file mode 100644 index 000000000..60ddd65ee Binary files /dev/null and b/kubernetes/assets/frontend.png differ diff --git a/kubernetes/assets/get-coredns.png b/kubernetes/assets/get-coredns.png new file mode 100644 index 000000000..b6d60d80f Binary files /dev/null and b/kubernetes/assets/get-coredns.png differ diff --git a/kubernetes/assets/mongo.png b/kubernetes/assets/mongo.png new file mode 100644 index 000000000..a41404035 Binary files /dev/null and b/kubernetes/assets/mongo.png differ diff --git a/kubernetes/assets/namespace create.png b/kubernetes/assets/namespace create.png new file mode 100644 index 000000000..1b6b3193d Binary files /dev/null and b/kubernetes/assets/namespace create.png differ diff --git a/kubernetes/assets/nodes.png b/kubernetes/assets/nodes.png new file mode 100644 index 000000000..172613405 Binary files /dev/null and b/kubernetes/assets/nodes.png differ diff --git a/kubernetes/assets/pv.png b/kubernetes/assets/pv.png new file mode 100644 index 000000000..5581e8027 Binary files /dev/null and b/kubernetes/assets/pv.png differ diff --git a/kubernetes/assets/pvc.png b/kubernetes/assets/pvc.png new file mode 100644 index 000000000..ae6ffa833 Binary files /dev/null and b/kubernetes/assets/pvc.png differ diff --git a/kubernetes/assets/redis.png b/kubernetes/assets/redis.png new file mode 100644 index 000000000..0fd0922fc Binary files /dev/null and b/kubernetes/assets/redis.png differ diff --git a/kubernetes/backend.yaml b/kubernetes/backend.yaml new file mode 100644 index 000000000..052559bd4 --- /dev/null +++ b/kubernetes/backend.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend-deployment + namespace: wanderlust + labels: + app: backend +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + name: backend + labels: + app: backend + spec: + containers: + - name: backend + image: madhupdevops/wanderlust-backend-beta:v2.1.0 + ports: + - containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: backend-service + namespace: wanderlust +spec: + type: NodePort + selector: + app: backend + ports: + - port: 8080 + targetPort: 8080 + protocol: TCP + nodePort: 31100 diff --git a/kubernetes/frontend.yaml b/kubernetes/frontend.yaml new file mode 100644 index 000000000..944f704c7 --- /dev/null +++ b/kubernetes/frontend.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend-deployment + namespace: wanderlust + labels: + app: frontend +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + name: frontend + labels: + app: frontend + spec: + containers: + - name: frontend + image: madhupdevops/wanderlust-frontend-beta:v2.1.0 + ports: + - containerPort: 5173 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend-service + namespace: wanderlust +spec: + selector: + app: frontend + type: NodePort + ports: + - port: 5173 + targetPort: 5173 + protocol: TCP + nodePort: 31000 diff --git a/kubernetes/kubeadm.md b/kubernetes/kubeadm.md new file mode 100644 index 000000000..ebfa20402 --- /dev/null +++ b/kubernetes/kubeadm.md @@ -0,0 +1,101 @@ +## Setup Kubernetes [Kubeadm] Cluster (Version: 1.29) + +### On both master & worker nodes +- Become root user +```bash +sudo su +``` + +- Updating System Packages +```bash +sudo apt-get update +``` + +- Installing Docker +```bash +sudo apt install docker.io -y +``` +```bash +sudo chmod 777 /var/run/docker.sock +``` + +- Create a shell script 1.sh and paste the below code and run it : +```bash +#!/bin/bash +# disable swap +sudo swapoff -a + +# Create the .conf file to load the modules at bootup +cat < Create a shell script 2.sh and paste the below code and run it +```bash +sudo kubeadm config images pull + +sudo kubeadm init + +mkdir -p "$HOME"/.kube +sudo cp -i /etc/kubernetes/admin.conf "$HOME"/.kube/config +sudo chown "$(id -u)":"$(id -g)" "$HOME"/.kube/config + + +# Network Plugin = calico +kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.0/manifests/calico.yaml + +kubeadm token create --print-join-command +``` + +### On Worker node +- Paste the join command you got from the master node and append --v=5 at the end + +```bash + --v=5 +``` + + diff --git a/kubernetes/mongodb.yaml b/kubernetes/mongodb.yaml new file mode 100644 index 000000000..c8473bbfd --- /dev/null +++ b/kubernetes/mongodb.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongo-deployment + namespace: wanderlust + labels: + app: mongo +spec: + replicas: 1 + selector: + matchLabels: + app: mongo + template: + metadata: + name: mongo + labels: + app: mongo + spec: + containers: + - name: mongo + image: mongo + ports: + - containerPort: 27017 + volumeMounts: + - name: mongo-storage + mountPath: /data/db + volumes: + - name: mongo-storage + persistentVolumeClaim: + claimName: mongo-pvc + +--- +apiVersion: v1 +kind: Service +metadata: + name: mongo-service + namespace: wanderlust +spec: + selector: + app: mongo + ports: + - port: 27017 + targetPort: 27017 + protocol: TCP diff --git a/kubernetes/persistentVolume.yaml b/kubernetes/persistentVolume.yaml new file mode 100644 index 000000000..e58ed86b8 --- /dev/null +++ b/kubernetes/persistentVolume.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: mongo-pv + namespace: wanderlust +spec: + capacity: + storage: 5Gi + volumeMode: Filesystem + accessModes: + - ReadWriteOnce + hostPath: + path: /data/db diff --git a/kubernetes/persistentVolumeClaim.yaml b/kubernetes/persistentVolumeClaim.yaml new file mode 100644 index 000000000..ea1b97509 --- /dev/null +++ b/kubernetes/persistentVolumeClaim.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mongo-pvc + namespace: wanderlust +spec: + accessModes: + - ReadWriteOnce + storageClassName: "" + resources: + requests: + storage: 5Gi diff --git a/kubernetes/redis.yaml b/kubernetes/redis.yaml new file mode 100644 index 000000000..06d74d6a4 --- /dev/null +++ b/kubernetes/redis.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis-deployment + namespace: wanderlust + labels: + app: redis +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + name: redis + labels: + app: redis + spec: + containers: + - name: redis + image: redis + ports: + - containerPort: 6379 + volumeMounts: + - name: mongo-storage + mountPath: /var/lib/redis/dump.rdb + volumes: + - name: mongo-storage + persistentVolumeClaim: + claimName: mongo-pvc +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-service + namespace: wanderlust +spec: + selector: + app: redis + ports: + - port: 6379 + targetPort: 6379 + protocol: TCP