Certified Jenkins Engineer

Kubernetes and GitOps

CICD with GitOps

GitOps streamlines Kubernetes deployments by keeping your cluster’s desired state in Git and automating synchronization. In this guide, you’ll learn how to structure your repositories, set up a CI/CD pipeline, and leverage ArgoCD for continuous delivery and rollbacks.

GitOps Repository Architecture

A typical GitOps workflow relies on two separate Git repositories:

Repository TypeContentsPurpose
Application RepositorySource code, configuration files, certificates, optional container images in GitTriggers CI builds and houses application assets
Configuration (Manifests) RepoKubernetes YAML manifests for Deployments, Services, ConfigMaps, SecretsSingle source of truth for cluster state

Note

Keep secrets out of Git or use an external secrets manager. Never store plain-text credentials in your manifests.

ArgoCD: The GitOps Operator

ArgoCD runs inside your Kubernetes cluster and continuously:

  1. Monitors the configuration repository for changes
  2. Pulls updated manifests
  3. Applies those manifests to synchronize cluster state with Git

This pull-based model ensures safe and auditable deployments.

CI/CD Pipeline Workflow

When a developer pushes changes to the application repository (for example, updating code or adding a Jenkinsfile), a CI/CD pipeline—often implemented in Jenkins—executes the following stages:

StageDescription
Unit TestsRun npm test, pytest, or equivalent
Build Docker Imagedocker build -t myapp:${VERSION} .
Push to Docker Registrydocker push myapp:${VERSION}

Once the new image is published, the pipeline must update the deployment manifests and trigger a GitOps deployment:

  1. Clone the configuration repository
  2. Modify the image tag in deployment.yaml
  3. Commit changes to a feature branch
  4. Open a Pull Request against main

A reviewer validates the change, then merges it. ArgoCD detects the merge and deploys the updated application.

Warning

Avoid force-pushing to the default branch. Always use pull requests to maintain an auditable history.

Rolling Back

ArgoCD’s history and rollback features enable you to revert to a stable release in minutes:

# View revision history for your application
argocd app history <app-name>

# Roll back to a specific revision
argocd app rollback <app-name> <revision-number>

This reapplies the manifest from the chosen revision, restoring your cluster to that state.

The image illustrates a CI/CD pipeline with GitOps, showing the flow from application code repository through continuous integration, updating Kubernetes manifests, and synchronizing with a production cluster using ArgoCD.

Demo Preview

In the upcoming demos, you will:

  • Create a Jenkinsfile defining all pipeline stages
  • Open a pull request to update the Kubernetes manifests repository
  • Watch ArgoCD synchronize changes and perform rollbacks if necessary

Watch Video

Watch video content

Previous
ArgoCD Concepts Terminology