Sunday, August 31, 2025

Cloud CI-CD Cheat Sheet II

In the previous post, we checked out Cloud CI/CD Cheat Sheet to transition from the 1990s to modern day CI/CD. Now lets integrate GitLab with GitFlow SDLC to demonstrate the Kubernetes CI/CD pipeline benefits.

Let's check it out!

GitLab CI/CD
 •  Create .gitlab-ci.yml at the root of project
 •  this is the driver file that co-ordinates stages:
 •  Build / Lint / Deploy

gitlab-ci.yml


Variables
 •  Generic Variables used in all environments and environment specific variables to build software
 •  Rules that can be used to automate deployments to "lower" environments vs. Manual deployments
 •  YAML that builds the Docker image and push image to container registry of the developer's choice
 •  YAML that has instructions on how to deploy latest built Docker image to Kubernetes cluster

 environments.yml  deployment-rules.yml

Artefacts
 •  YAML files that contain Helm chart artefacts used like Deployment and Service YAML
 •  YAML files that contain Values to be injected including environment specific variables

 deployment.yaml  service.yaml

NOTE: Hardcoded non-sensitive variables stored in Values YAML files including all environment variables:

Whereas sensitive information is stored in Kubernetes secret resources and injected at deployment time.

GitFlow SDLC
Development
 •  GitLab source code repo has main branch for all the Prod deployments
 •  GitLab source code repo has develop branch as the integration branch
 •  develop branch for feature development and deployment to DEV / UAT
 •  GitFlow: ensure develop branch is stable: cut feature branch off develop

Deployment
 •  Submit Pull Request | Merge to develop branch | Trigger build
 •  Auto-deploy to DEV | Manual deploy to UAT [when QA ready]

Testing
 •  Feature completed on DEV / preliminary testing on UAT cut release branch off develop
 •  Deploy release branch to UAT - complete feature testing and regression testing
 •  Any bugs on UAT in release candidate then cut bugfix branch off release branch
 •  Fix bug | Submit Pull Request | Merge to release branch | Re-deploy to UAT [manually]

Release
 •  Once release candidate is stable / all bugs fixed: then submit Pull Request release branch to main
 •  This action will build pipeline but NOT deploy!! Manually deploy to Prod when stakeholders agree!!


Alignment
 •  Finally, after deploy to Prod from main submit PR from main to develop for alignment
 •  Hotfixes available similar to bugfix | Cut hotfix branch from main and submit PR deploy to Prod
 •  After hotfix merged to main and deployed to Prod submit PR from main to develop for alignment


Kubernetes Management: Rancher
Q. What is Rancher?
Open source platform that simplifies the deployment, scaling and management of your Kubernetes clusters:
 •  Kubernetes: open source orchestration platform that automates management of containerized apps
 •  Rancher: open source container platform built on top of Kubernetes to simplify cluster management
 •  Download Kubernetes cluster configuration kubeconfig files from Rancher to connect to your clusters


Kubernetes kubeconfig
 •  kubeconfig file is YAML configuration used to connect to Kubernetes clusters, users and contexts
 •  Download DEV kubeconfig file from Rancher to localhost ~/.kube/dev-config
 •  Download UAT kubeconfig file from Rancher to localhost ~/.kube/uat-config

SETUP
  # Setup the global KUBECONFIG environment variable
  export KUBECONFIG=~/.kube/config:~/.kube/dev-config:~/.kube/uat-config
  # Flatten multiple kubeconfig files into one "master" kubeconfig file
  kubectl config view --flatten > one-config.yaml
  # Rename accordingly
  mv one-config.yaml ~/.kube/config
  # Confirm cluster configuration update
  kubectl config get-contexts


Deployment Verification
Monitor cluster - What is kubectl?
 •  Command line tool run commands against Kubernetes clusters - communicate using Kubernetes API
 •  Post-deployment use kubectl commands to verify the health of cluster ensuring all pods re-spawned


TEST Deployment
Finally, test endpoint(s) via curl or in Postman:
  # Test endpoint
  kubectl port-forward service/flask-api-service 8080:80
  curl http://localhost:8080/api/v1 --header "Content-Type: application/json"
  # RESPONSE
  {"message": "Hello World (Python)!"}


CI/CD Pipeline Benefits
Four Benefits of CI/CD - successful pipeline strategy helps your team deliver higher quality Software faster!
 •  Increased speed of innovation + automation = deployments that are faster and more regular
 •  Code in Production adds immediate value instead of sat waiting in a deployment queue!
 •  Engineers become more productive instead of focus on boring / mundane manual tasks
 •  Higher code quality due to continuous automated build, test, deploy rinse + repeat cycles J

Summary
To summarize, we have now highlighted the back story transitioning from the 1990s to modern day CI/CD and outlined the integration process with GitFlow SDLC to demonstrate Kubernetes CI/CD pipeline benefits!