-
Clone the project from github
-
open terminal and cd deployment/docker
-
Setup the following services and get the corresponding keys
- Create an account on mongodb atlas, create a cluster, db and get a mongo srv string
- Setup cloudinary account and get your account name
- Setup Strip developer account and get Strip secret key.
-
Run the exports to set in the terminal
export MONGO_SRV=<YOUR MONGO SRV> export JWT_SECRET="notsosecret" export CLOUDINARY_URL="https://api.cloudinary.com/v1_1/<YOUR ACCOUNT NAME>/image/upload" export STRIPE_SECRET_KEY=<YOUR STRIPE SECRET KEY> export PORT=8080 export NODE_ENV=production export CLOUDWATCH_GROUP_NAME=ecommerce-store export CLOUDWATCH_ACCESS_KEY=<ACCESS_KEY_ID> export CLOUDWATCH_SECRET_ACCESS_KEY=<ACCESS_KEY_SECRET> export CLOUDWATCH_REGION=us-east-1
-
Run the docker compose build
docker-compose -f docker-compose-build.yaml build --parallel
- Run docker compose up command to start the containers.
docker-compose up
-
Create a EKS Cluster in the AWS Console with name ecommerce-app.
-
Configure EKS Cluster using AWS cli and check as shown in image below.
aws eks --region us-east-1 update-kubeconfig --name ecommerce-app
- Check the cluster info using below command as shown in image above.
kubectl cluster-info
- Add a nodegroup to the EKS cluster using the "Add Node Group" section in the "Compute" tab
- Refresh the AWS page to check the node group is created.
- Once node group is created check the status of nodes in cluster using following command
kubectl get nodes
- Create k8 Secrets and ConfigMap
kubectl apply -f env-secret.yaml
kubectl apply -f env-configmap.yaml
- Apply Backend Deployment and Service yaml
kubectl apply -f backend-deployment.yaml
kubectl apply -f backend-service-lb.yaml
- Check the status of Backend pods
kubectl get pods
- Check the status of Backend services
kubectl get services
- Verify the backend api's are working fine using the loadbalancer host
- Update the next.config.js file in the config with the loadbalanced backend service url.
// must restart server whenever you make changes in next.config
module.exports = {
serverRuntimeConfig: {
// Will only be available on the server side
apiUrl: `http://a3827adb053c34a168d8755893c9e93e-283059086.us-east-1.elb.amazonaws.com:8080`,
},
publicRuntimeConfig: {
// Will be available on both server and client
apiUrl: `http://a3827adb053c34a168d8755893c9e93e-283059086.us-east-1.elb.amazonaws.com:8080`,
},
};
- Commit the changes to trigger the new Frontend build and image creation.
- Check the Docker hub has the latest images.
14. Apply Frontend Deployment and Service yaml
- Create Deployment and Service for the frontend server.
kubectl apply -f frontend-deployment.yaml
kubectl apply -f frontend-service-lb.yaml
- Check the status of Frontend pods
kubectl get pods
- Check the status of Frontend services
kubectl get services