Build & Deploy Series | Part-4 | Build and Deploy of React Application in Kubernetes using BASH hosted on AWS EC2
Highly Recommend using repo here - Day4 to practise this project instead of code present in snippets, In case of confusion, Please do watch video that is explained in English, the code here in the blog is not changed to keep screenshots intact
Before we begin with this, i would highly recommend you to watch Part-2 and Part-3 of Series
Configuration to be used for this project:
Build of React Application
Now our goal here is to Build docker image in AWS EC2 server and push it to Docker hub
we will write a simple bash script to automate our process
we will be deleting our existing images to save some space, generally this is not recommended, i am running this as i don't want to get space issue for docker images to be piled up whenever we run build
we can pull the existing repository, but in this, i am deleting and re-creating git to update latest repository
i am running the script as i can use the same script to deploy in new servers if needed
You can also use the repo here as an alternate
git clone https://github.com/sagarkakkalasworld/Day4
#!/bin/bash
sudo docker rmi -f $(sudo docker images -q) ##this is not recommned step, i am deleting existing images to save space
sudo rm -r gold ## these steps are not recommened instead you can modify script as shown below
sudo mkdir gold
cd gold/
sudo git clone https://github.com/Hari0o/Gold_Site_Ecommerce.git
cd Gold_Site_Ecommerce/
sudo docker build -t react-nginx -f golddockerfile .
sudo docker tag react-nginx:latest reactdemo/react-nginx:latest ##make sure you did docker login
sudo docker push reactdemo/react-nginx:latest
##recommended script###
#!/bin/bash
#cd gold/Gold_Site_Ecommerce
#sudo git pull
#sudo docker build -t react-nginx -f goldockerfile .
#sudo docker tag react-nginx:latest reactdemo/react-nginx:latest ##make sure you did docker login
#sudo docker push reactdemo/react-nginx:latest
sudo chown ubuntu build.sh
sudo chmod 744 build.sh
/home/ubuntu/build.sh
sudo docker images
Deployment of React Application
#!/bin/bash
pods_id=$(microk8s kubectl get pods -n react-nginx |grep react |awk {'print $1'})
microk8s kubectl delete pod $pods_id -n react-nginx
sudo chown ubuntu deploy.sh
sudo chmod 744 deploy.sh
./deploy.sh
kubectl get pods -n react-nginx
Domain visibility
Go for AWS EC2, security groups and In inbound rules allow port 80, as our nginx listens on port 80
post that copy AWS EC2 public IP,
log in to your Godaddy Console, and My products > Domain > DNS
In A records, paste the AWS EC2 public IP we have created
Now we will be able to access our domain in which we can see our React application that we have built
and deployed
note: AWS public IP changes once the system is stopped and started back. to avoid this,
you can use AWS Elastic IP with some cost charges
Note: Domain visibility is not recommended if you have not restarted your instance or Using AWS Elastic IP
Comments
Post a Comment