GCP DevOps Project

Sprint 07

Sprint 07

In Sprint 07, we’ll enhance our GKE-based CI/CD pipeline by introducing a dedicated development environment. This sandbox allows developers to validate changes safely before they reach production.

Objectives

  • Create a development namespace in the GKE cluster.
  • Configure branch-based deployments:
    • Pushing to the development branch deploys to the development namespace.
    • Merging into the main branch deploys to production.

Whenever a developer pushes code to development, the pipeline triggers a rollout into the dev namespace. After tests and QA pass, merging into main initiates the production release.

Note

A development environment provides an isolated namespace in your GKE cluster for testing and validation of changes without impacting production.
Learn more in the Kubernetes Namespaces documentation.

The image shows a search bar with the query "What is a development environment?"

The image is a flowchart illustrating a process from "Application" to "Main Branch," with steps including "Development" and "Development Environment." Each step is represented by an icon within a circle.

Branch-to-Namespace Mapping

Git BranchKubernetes NamespaceTrigger Event
developmentdevgit push to develop
mainproductionPull request merge into main

Updating the CI/CD Pipeline

Most CI/CD stages stay the same; we’ll only adjust:

  1. Namespace creation steps.
  2. Deployment job triggers.

1. Create the Development Namespace

kubectl create namespace dev

2. Update Pipeline Configuration

In your CI/CD YAML (e.g., Cloud Build or GitHub Actions), add branch filters:

# Example GitHub Actions snippet
on:
  push:
    branches:
      - development
  pull_request:
    branches:
      - main

jobs:
  deploy-dev:
    if: github.ref == 'refs/heads/development'
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to Dev Namespace
        run: |
          kubectl config use-context gke-cluster
          kubectl apply -f k8s/ --namespace=dev

  deploy-prod:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to Production
        run: |
          kubectl config use-context gke-cluster
          kubectl apply -f k8s/ --namespace=production

Next Steps

  1. Validate the development environment by pushing a test commit to development.
  2. Review logs and confirm the new namespace deployment.
  3. Merge into main and watch the production rollout.

For more on CI/CD best practices with Kubernetes, see the Kubernetes CI/CD guide.

Watch Video

Watch video content

Previous
Sprint 06 review