Skip to content

Building docker application and push the image to GCR and deploy this application on GKE cluster and expose the application with HTTP load balancer, All infrastructure provisioned by Terraform

Notifications You must be signed in to change notification settings

Magdi888/GCP-Project

Repository files navigation

GCP Project

Requirements:

  • The Application to be dockerized and pushed to GCR is on here: Code
  • Provision infrastructure on GCP with Terraform Consist of:
    • VPC with two subnets:
      • Management subnet has:
        • Private VM.
        • NAT gateway.
      • Restricted subnet has:
        • Private standard GKE cluster.
  • Deploy the application on the GKE cluster.
  • Deployment must be exposed to public internet with a public HTTP load balancer.

Description:

  • Restricted subnet must not have access to internet.
  • The VM must be private.
  • Deployment on GKE manually by kubectl tool.
  • Only the management subnet can connect to the GKE cluster.
  • Useing custom SA not the default one and attach it to our of GKE cluster nodes.

Steps:

Dockerize Python Web App from DevOps-Challenge-Demo-Code

  • Dockerfile Click here
  • Authenticate to push images to GCR
  gcloud auth configure-docker
  • Build image and tag it with gcr hostname and tag redis image with the same hostname and push them.
  docker build -t us.gcr.io/durable-spot-354112/webapp
  docker tag redis:5.0-alpine us.gcr.io/durable-spot-354112/redis
  docker push us.gcr.io/durable-spot-354112/webapp
  docker push us.gcr.io/durable-spot-354112/redis

Provision infrastructure on GCP with Terraform.

  • Create Bucket to save Terraform state file.
  • Set the bucket name in backend.tf file.
  • Run the following:
 # Initialization terraform
  terraform init
 # Show our Plan
  terraform plan --var-file dev.tfvars
 # Create Dev Workspace
  terraform workspace new dev
 # Select Dev Workspace
  terraform workspace select dev
 # Apply Our Plan
  terraform apply --var-file dev.tfvars

Infrastructure

Untitled Diagram-Page-1

  • Connect to Private VM with ssh.
  gcloud compute ssh [machine name]
  • Updates a kubeconfig file with appropriate credentials and endpoint information to point kubectl at a our cluster in Google Kubernetes Engine.
 gcloud container clusters get-credentials [GKE name] --zone [used zone] --project [ProjectId]

Deploying Our App on K8s resources

  • Copy K8s_resources directory to VM
  • Run command:
 kubectl create namespace dev
 kubectl apply -Rf ./K8s_resources -n dev

Web App Structure

Untitled Diagram-Page-2 drawio (1)

  • Get Web App IP
 kubectl get ingress

image

  • Visit Ingress Address:Port [34.110.182.92:80]

image

About

Building docker application and push the image to GCR and deploy this application on GKE cluster and expose the application with HTTP load balancer, All infrastructure provisioned by Terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published