- Build docker image with simple apache and static web page locally
- Provision GKE cluster manually and deploy image manually
- Provision GKE cluster using Terraform from local
- Deploy image into the cluster using Kubernetes manifests from local
- Create build and deploy pipeline using Cloud Build
Below information assumes that the first two objectives are already completed.
- ./terraform - Terraform files
- ./k8s - Kubernetes manifests
- ./docker - Dockerfile
- ./public-html - Static web page
- Follow Hashicorp training: https://learn.hashicorp.com/terraform/gcp/intro
- Follow Google Terraform documentation: https://cloud.google.com/community/tutorials/managing-gcp-projects-with-terraform
- Do not store credentials file inside the repo
If using Makefile, set local environment variables in .env file. Rename template.env into .env and set variables.
PROJECT_ID=gcp_project_id
CLUSTER=gke_cluster_name
TF_STATE_BUCKET=terraform_state_bucket
GOOGLE_APPLICATION_CREDENTIALS=path_to_gcp_creds_file
Alternatively set variables directly inside shell.
Once GCP project and Terraform are setup run the following to provision GKE cluster and deploy app.
- Run
make provision
- Tear down
make destroy
Alternatively run commands from Makefile.
By default Terraform state will be local. In this lab we create remote state in GCP storage bucket.
- Create storage bucket for terraform state
gsutil mb -c standard -l us-central1 gs://globaly-unique-bucket-name
- Run
terraform init
Now we can use Cloud Build to deploy the app.
The first stage is to provision GKE cluster, then deploy the app. We describe it inside cloudbuild.yaml
- Connect your github repo to Cloud Repo.
- Make sure that Cloud Build service account has enough permissions for Kubernetes Engine and Compute Engine. Use Cloud Build Settings and IAM console to configure.
- Go to Code Build and create a push trigger for the repo
- Now every git push should trigger a build. Watch logs.