Automated GCP Deployment: Cloud Build and GKE Autopilot Integration

Deploy applications via automated pipelines using Cloud Build and GKE Autopilot. This configuration reduces manual intervention and ensures consistent infrastructure scaling.

This guide details the configuration of a one-click deployment for an Nginx service on Google Cloud Platform (GCP). The procedure covers creating a GKE Autopilot cluster, retrieving cluster credentials, and executing the application deployment.

Prerequisites

Configuration Overview

The deployment process follows these steps:

  1. Set the GCP project.
  2. Create a GKE Autopilot cluster using Cloud Build and Deployment Manager.
  3. Retrieve credentials for the new cluster.
  4. Deploy an Nginx service using kubectl.

Setup and Execution Procedure

Process Flow Diagram

Diagram of three YAML files from GitHub driving Cloud Build, Deployment Manager, Kubernetes Engine and an nginx deployment

1. Cloud Build configuration

The cloudbuild.yaml file defines the build steps. It controls the deployment sequence.

Code screenshot of cloudbuild.yaml step 1, which sets the Google Cloud project with gcloud config set project
Code screenshot of cloudbuild.yaml steps that create the deployment, get cluster credentials and apply the nginx YAML

2. Deployment Manager configuration

The gke_autopilot.yaml file sets the cluster properties. It defines the GKE Autopilot configuration.

Code screenshot of gke_autopilot.yaml defining a GKE cluster resource with its project, region and node count

3. Nginx deployment configuration

The nginx-deployment.yaml file defines two resources:

Code screenshot of nginx-deployment.yaml, a Kubernetes Deployment running one nginx:latest replica on port 80
Code screenshot of a Kubernetes Service of type LoadBalancer that exposes nginx on TCP port 80

Deployment Steps

  1. Configure cloudbuild.yaml:
    • Define Cloud Build steps to deploy resources.
    • Follow the structure shown above.
  2. Configure gke_autopilot.yaml:
    • Specify GKE Autopilot cluster properties.
  3. Configure nginx-deployment.yaml:
    • Define the Nginx deployment.
    • Define the service.
  4. Trigger the build

Use the Google Cloud Console or the following command to start the build:

Terminal command gcloud builds submit --config cloudbuild.yaml that starts the Cloud Build run

Cloud Build runs the steps in order. It creates the GKE Autopilot cluster, retrieves credentials, and deploys Nginx.

Summary

This setup uses Cloud Build and GKE Autopilot to simplify deployment. The cloudbuild.yaml file defines the steps. It handles project configuration, cluster setup, and application deployment. This approach is efficient and automated.

For help with Google Cloud deployments, see our Google Cloud migration services.

Related reading: how to migrate a database to GCP and how to set up a data pipeline on GCP.