GCP DevOps Project

Sprint 03

CICD Design Discussion

Streamlining your software delivery with a robust CI/CD pipeline ensures that every code change in GitHub is automatically built, tested, and deployed to Google Kubernetes Engine (GKE). This guide walks through planning, building, storing, and deploying Docker images to GKE using Kubernetes manifests.

Key Pipeline Questions

  1. How do we automate Docker image builds?
  2. Where should we store Docker images?
  3. How do we deploy images to GKE with Kubernetes manifests?

1. Automating Docker Image Builds

Manual Docker builds after each commit are not scalable. We need an automated build system that triggers on every Git push.

Note

Popular CI/CD tools for GitHub integrations include GitHub Actions and Google Cloud Build.

Example snippet for a Cloud Build trigger (cloudbuild.yaml):

steps:
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-app:$SHORT_SHA', '.']
images:
  - 'gcr.io/$PROJECT_ID/my-app:$SHORT_SHA'

2. Storing Docker Images

After building, push your image to a registry. Below is a comparison of popular options:

Registry TypeUse CaseExample Push Command
Docker HubPublic/Open Source projectsdocker push myuser/my-app:latest
Google Artifact Registry/RegistryPrivate GCP workloadsdocker push gcr.io/my-project/my-app:latest
Self-hosted RegistryOn-prem or hybrid deploymentsdocker push registry.mycompany.com/my-app:stable

Warning

Ensure proper IAM roles or credentials are configured before pushing images. Avoid embedding credentials in your repository.


3. Deploying to GKE with Kubernetes Manifests

Kubernetes manifests define how your application runs in GKE. At minimum, you need:

  • Deployment: Manages pods and updates
  • Service: Exposes pods inside/outside the cluster

The image illustrates a process involving GitHub and GKE, with a central message about writing deployment/service YAML files for Kubernetes deployment.

Common Kubernetes Resources

Resource TypeDescriptionExample CLI
DeploymentDeclarative update for Podskubectl apply -f deployment.yaml
ServiceStable network endpoint for Podskubectl apply -f service.yaml
Horizontal Pod Autoscaler (HPA)Automatic scaling based on CPU/memorykubectl apply -f hpa.yaml
IngressHTTP routing into the clusterkubectl apply -f ingress.yaml

Beyond the basics, you can add:

The image shows four icons representing Kubernetes concepts: Horizontal Pod Autoscaling, Ingress, Deployment, and Service YAML. Each icon is labeled accordingly.


4. End-to-End CI/CD Workflow

Combine build, storage, and deployment into a single automated flow:

  1. Detect changes in the GitHub repository (e.g., on main branch).
  2. Trigger build: Run Docker build, run tests, and tag the image.
  3. Push image to the artifact registry.
  4. Deploy to GKE: kubectl apply -f the updated YAML manifests.

The image outlines a process involving GitHub and GKE, detailing steps for automating Docker image builds, storing them in an artifactory, writing deployment YAML files, and setting up continuous deployment.


5. Research and Collaboration

Before implementation, perform a research phase to refine your CI/CD strategy:

  • Review Google Cloud Build documentation for CI/CD best practices.
  • Explore open-source pipeline examples on GitHub.
  • Audit existing Kubernetes YAML files to learn naming conventions and labels.
  • Collaborate with senior engineers to validate security and scalability requirements.

The image is a flowchart illustrating a process involving GCP documentation, deployment, a GitHub repository, YAML files, and an answer, with associated actions like using a CI/CD tool, research, open source, and reading code.


With these design considerations, you’re ready to implement a fully automated CI/CD pipeline that builds, stores, and deploys Docker images to GKE. Good luck!

Watch Video

Watch video content

Previous
Sprint 03