Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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 :
sudo su

  1. Clone code from remote repository (GitHub) :
git clone -b devops https://github.com/DevMadhup/wanderlust.git

  1. Verify nodes are in ready state or not :
kubectl get nodes

Alt text

  1. Create kubernetes namespace :
kubectl create namespace wanderlust

Namespace

  1. Update kubernetes config context :
kubectl config set-context --current --namespace wanderlust

Update context

  1. 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
kubectl get pods -n kube-system -o wide | grep -i core

Alt text

  • Above step will run coredns pod on worker node as well for DNS resolution
kubectl edit deploy coredns -n kube-system -o yaml

Make replica count from 2 to 4

replica 4

  1. Navigate to frontend directory :
cd frontend

  1. Edit .env.docker file and change the public IP Address with your worker node public IP :
vi .env.docker

IP

  1. Build frontend docker image :
docker build -t madhupdevops/frontend-wanderlust:v2.1.8 .

Dockerfile frontend

  1. Navigate to backend directory :
cd ../backend/

  1. Open .env.docker file and edit below variables :

    • MONGODB_URI: <your-mongodb-servicename>
    • REDIS_URL: <your-redis-servicename>
    • FRONTEND_URL: <your-workernode-publicIP>

Note: To get service names, check mongodb.yaml, redis.yaml

Backend env file

  1. Build backend docker image :
docker build -t madhupdevops/backend-wanderlust:v2.1.8 .

Backend dockerfile

  1. Check docker images:
docker images

docker images

  1. Login to DockerHub and push image to DockerHub
docker login

docker login

docker push madhupdevops/frontend-wanderlust:v2.1.8
docker push madhupdevops/backend-wanderlust:v2.1.8

  1. Once, Image is pushed to DockerHub, navigate to kubernetes directory
cd ../kubernetes

  1. Apply manifests file the below order:

    • Create persistent volume :
    kubectl apply -f persistentVolume.yaml 

    Peristent volume

    • Create persistent volume Claim :
    kubectl apply -f persistentVolumeClaim.yaml 

    Peristent volume Claim

    • Create MongoDB deployment and service :
    kubectl apply -f mongodb.yaml 

    MongoDb

    • 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.

    kubectl apply -f redis.yaml 

    Redis

    • Create Backend deployment and service :
    kubectl apply -f backend.yaml 

    Backend

    • Create Frontend deployment and service :
    kubectl apply -f frontend.yaml

    Frontend

  1. Check all deployments and services :
kubectl get all

all deployments and services

  1. 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

kubectl logs <pod-name>
  1. Navigate to chrome and access your application at 31000 port :
http://<your-workernode-publicip>:31000/

App