Skip to content

ehienabs/databotsgcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DATABOTS

Databotsgcp describes the deployment of a simple app. Our app is to be deployed on Google’s Kubernetes Engine using Cloud Build for continuous integration & delivery, and terraform to codify the provisioning of our infrastructure.

Prerequisites

These are the prerequisites to get started

  • A GCP account
  • Terraform installed
  • Google SDK installed
  • Github Account

Provisioning our Infra

Terraform allows us express our infrastructure as code. It also attempts to sync our desired state of infrastructure (as declared in code) with the live state of our Infrastructure. Minor configurations can also be made with it.

Getting Started

We set the project properties for our gcloud cli using this command;

gcloud init

After filling in our configurations we enable the following APIs using this command;

gcloud services enable compute.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable container.googleapis.com
gcloud services enable servicenetworking.googleapis.com
gcloud services enable cloudbuild.googleapis.com

After enabling our APIs, we create a bucket to host our Terraform state remotely using this command;

gsutil mb gs:https://<BUCKET_NAME>

Annotation 2022-02-04 013840

Next we will give some authority to terraform to manage resources using this command;

gcloud auth application-default login

Note; This is for testing purposes only. In production, we will create a service account, assign fine permissions to it and store the key file in a secrets manager. We will then reference those credentials in our terraform configurations.

We initialize terraform using this command;

terraform init

Finally, we will provision our infra by running this command in the infra directory;

terraform apply

This creates a VPC, a subnet, a regional GKE cluster and stores the state in a bucket.

Annotation 2022-02-05 120130

Annotation 2022-02-05 120322

Annotation 2022-02-04 122020

CI/CD with Cloud Build

Cloud Build is a serverless service which executes builds on GCP as a series of steps as defined in a configuration file.

The builds are executed by Cloud Builders, which are themselves container images that allow you run commands.

Getting Started

We will define the following build steps in our build config file

  • Step one clones our remote repository using the git builder
  • Step two builds our container image using the docker builder
  • Step three pushes our container image to container register using docker builder
  • The final step applies our Kubernetes deployment manifest to our cluster using gke-deploy builder

Next we will give some authority to Cloud Build to manage our Kubernetes cluster using the following command;

gcloud projects add-iam-policy-binding <PROJECT> -<SERVICE_ACCOUNT>@cloudbuild.gserviceaccount.com --role=roles/container.developer

Cloud Build uses Triggers to automate CI/CD. GitHub Triggers automate builds in repositories using events such as pushes or pulls. After connecting our repository, we will create our Trigger using Push to Branch as the event trigger. This means that pushing any changes to our connected repository will trigger a build.

Annotation 2022-02-05 120833

Finally we push our app to the repository and let Cloud Build do its thing.

Annotation 2022-02-05 120605

Since our app is internet facing and exposed with a load balancer, we can reach it by using the Load Balancer IP or from our Services.

Annotation 2022-02-05 120632

Fin

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published