Building a stateful web app using GCP architecture to deploy it in the GKE cluster using Terraform as infrastructure as code (IaC)
-
Develop and use your own Terraform modules to build the required infrastructure on GCP:
- a. IAM: 2 service accounts - N roles.
- b. Network: 1 VPC – 2 subnets – N firewall rules – 1 NAT.
- c. Compute: 1 private VM – 1 GKE standard cluster across 3 zones.
- d. Storage: Artifact Registry repository to store the images.
-
Deploy the MongoDB replicaset across the 3 zones
-
Dockerize and Deploy the Node.js web app connected to the 3 DB replicas.
-
Expose the web app using ingress/load balancer.
- GCP Account
- Terraform
- docker
- kubectl
-
Build application image by docker file and push to artifact registry
-
Initialize infra using Terraform
terraform init terraform plan terraform apply --auto-approve
-
After creating the GCP architecture we have to ssh to private-vm through IAP
gcloud compute ssh [vm-name] --tunnel-through-iap --zone=[zone-name] --project=[project-id]
-
Once you connect to your private VM, you can access the GKE Cluster
gcloud container clusters get-credentials [cluster-name] --zone [zone-name] --project [project-id]
- Deploy MongoDB (stateful)
- Deploy Node.js app
- Deploy LoadBalancer service