Deploy in Minutes: A Quickstart Guide to CI/CD with GCP for Web Apps

Aleksei Aleinikov
5 min readFeb 8, 2024

Welcome! In this guide, I’ll show you how to deploy a web application using CI/CD on the Google Cloud Platform (GCP). We’ll be utilizing Kubernetes to manage our application and Cloud Build to automate the build and deployment process.

Step 1: Downloading the Repository

As a first step, please follow the link below to download my sample project repository from GitHub: GitHub Repository

After downloading the repository, we are ready to set up our Kubernetes cluster on GCP.

Step 2: Creating a Kubernetes Cluster on GCP

Now that we have downloaded the repository, let’s proceed with setting up our Kubernetes cluster on Google Cloud Platform (GCP). Follow these steps:

  1. Sign in to your Google Cloud Platform account.
  2. Navigate to “Kubernetes” in the navigation menu.
  3. Click on “Create Cluster.
  4. Specify a name (for example, “test-cluster”) and a region (for example, “us-central1”).
  5. Configure any other parameters or use the default values.
  6. After clicking “Create,” wait for the cluster creation to complete. This process may take 15–20 minutes. While the cluster is being created, we can proceed with other configurations.

Step 3: Creating an Artifact Registry:

Now let’s proceed with creating an Artifact Registry:

  1. Click on “Catalog” in the navigation menu.
  2. Enter “Artifact Registry” in the search bar or find it in the list of services.
  3. Click on “Create Repository.
  4. Specify the repository name (for example, “test-repository”) and choose the region (“us-central1”).
  5. Click on “Create” to complete the repository creation process.

6. Once the repository is created, navigate into it and copy the repository link.

For example, in my case with the project identifier “qwiklabs-gcp-00–2ad8e3085b3b”, the repository link would appear as follows:
us-central1-docker.pkg.dev/qwiklabs-gcp-00–2ad8e3085b3b/test-repository

7. Update the cloudbuild.yaml and app-deployment.yaml files by specifying the new repository link:

For app-deployment.yaml:

us-central1-docker.pkg.dev/qwiklabs-gcp-00–2ad8e3085b3b/test-repository/webapp:latest

For the cloudbuild.yaml file, in two places where the repository link is specified, use the following value:

us-central1-docker.pkg.dev/qwiklabs-gcp-00–2ad8e3085b3b/test-repository/webapp.

Step 4: Creating a Cloud Build Trigger:

  • Sign in to Google Cloud Console and navigate to “Cloud Build” > “Triggers”.
  • Click on the “Create Trigger” button.
  • Choose the source repository, such as your GitHub repository, and follow the instructions to connect your repository to Cloud Build.
  • Specify the branch in the trigger settings, for example, main or master, to which Cloud Build will respond.
  • Set a name for the trigger, for example, “push-to-main”. By creating this trigger, you will configure automatic execution of the Cloud Build process when the specified branch of your repository is updated.

Step 5: Setting up a Connection with Cloud Build Account:

gcloud projects add-iam-policy-binding $(gcloud config get-value project) \ --member=serviceAccount:$(gcloud projects describe $(gcloud config get-value project) --format="value(projectNumber)")@cloudbuild.gserviceaccount.com \ --role=roles/container.developer

This command establishes a connection between your project in Google Cloud and the service account for Cloud Build. It provides the Cloud Build service account with the necessary permissions to work with containers and Kubernetes Engine in your project.

Step 6: Setting up kubectl for Cluster Interaction: After creating the cluster, follow these steps:

  1. Open Cloud Shell on Google Cloud Platform.
  2. Execute the command:
gcloud container clusters get-credentials <cluster_name> --zone <zone_name> --project <project_id>

In my example, it will be:

gcloud container clusters get-credentials test-cluster --zone us-central1 --project qwiklabs-gcp-00-2ad8e3085b3b

Now that kubectl setup is complete, you can execute Kubernetes commands, such as kubectl get pods, directly in Cloud Shell to retrieve the list of pods in your cluster.

Step 7: After committing and pushing to the main (master) branch, follow these steps:

  • Check the Cloud Build execution result. Ensure that the build process was successful.
  • After successful build, verify the status of the pods. Make sure that the pods were created and started successfully.
  • Check the Kubernetes services. Copy the external IP address of the service and navigate to the link in your browser.
  • After navigating to the link, ensure that your website is successfully displayed.

As we wrap up this article, you’ve successfully deployed your website using microservices on Google Cloud Platform. This process illustrates the principles of continuous delivery (CI/CD) and containerization for application deployment. We’ve covered each stage, from infrastructure setup to automated build and deployment, making your projects more scalable, reliable, and maintainable. By leveraging GCP tools, you now have access to robust infrastructure to develop and deploy your applications successfully. If you found this article helpful, please consider supporting me by giving it a like or star on GitHub. Your feedback will help other users discover the usefulness of this content. Thank you for your attention, and I hope the information has been valuable to you!

To connect with me or discuss this article further, feel free to reach out on LinkedIn.

#GoogleCloud, #CICD, #DevOps, #GCP, #CloudBuild.

--

--

Aleksei Aleinikov
0 Followers

Expert Software Engineer | Python, JavaScript, React | AI, GCP | Data Engineering, Data Analysis, Business Intelligence