GCP DevOps Project

Sprint 07

Upgrade replicas using the new flow

Overview

In this guide, you’ll learn how to scale your GKE Deployment from 1 to 3 replicas using a GitOps-based workflow. Instead of applying changes directly to production, we will:

  1. Update the development branch via the GitHub UI
  2. Trigger a Cloud Build pipeline
  3. Verify changes in the dev environment
  4. Promote to the main branch for production rollout

This approach ensures reliable deployments and aligns with DevOps best practices, improving both velocity and confidence.

Prerequisites

  • A Google Cloud project with GKE cluster deployed
  • A Cloud Build trigger configured to deploy the development branch
  • Permissions to modify GitHub repositories and view Cloud Build logs

Step 1: Update the Deployment via GitHub UI

Note

Hotfixes via the GitHub UI can be useful for quick changes, but in production environments it's recommended to use pull requests and code reviews.

  1. Switch to the development branch in your GitHub repo.
  2. Navigate to gke.yaml.
  3. Change the replicas field from 1 to 3:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gcp-devops-gke
spec:
  replicas: 3
  selector:
    matchLabels:
      app: gcp
  template:
    metadata:
      labels:
        app: gcp
    spec:
      containers:
        - name: gcp-devops-gke
          image: gcr.io/kodekloud-gcp-training/gcpdevops-dev:latest
          ports:
            - containerPort: 5000
          env:
            - name: PORT
              value: "5000"
---
apiVersion: v1
kind: Service
metadata:
  name: gcp-devops-gke-service
  namespace: gcp-devops-dev
  labels:
    app.kubernetes.io/managed-by: gcp-cloud-build-deploy
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5000
  1. Commit and push your changes. This action triggers the Cloud Build pipeline.

Step 2: Monitor the Cloud Build Pipeline

After pushing the commit, navigate to the Cloud Build Console to follow the build steps. The pipeline typically includes:

StepDescription
Fetch SourceClone the development branch
Build ImageBuild and push Docker image to GCR
Deploy to GKEApply updated manifests to GKE

The image shows a Google Cloud Build interface displaying the details of a running build process, including steps and logs related to Docker and GKE deployment.

Warning

Ensure your Cloud Build service account has the required IAM roles for deploying to GKE.

Step 3: Verify the Deployment in Dev Environment

  1. Open the Google Cloud Console.
  2. Navigate to Kubernetes Engine > Workloads.
  3. Select the gcp-devops-gke workload in the gcp-devops-dev namespace.

The image shows the Google Cloud Console's Kubernetes Engine interface, displaying a workload named "gcp-devops-gke" with a status of "OK" and 3/3 pods running. The terminal at the bottom is open in the Cloud Shell environment.

You should see all three pods in the Running state. Perform any required functionality or load tests to validate the scaling update.

Step 4: Promote Changes to Production

Once the dev environment tests pass:

  1. Switch to the main (or production) branch.
  2. Repeat the replica count update in gke.yaml.
  3. Commit and push to trigger the production build and deployment.

This promotes consistency across environments and ensures a smooth rollout.

Conclusion

By following this GitOps-style workflow, you can safely scale your GKE workloads, reduce manual errors, and enhance your deployment automation.

References

Watch Video

Watch video content

Previous
Extending development environment 02