Certified Jenkins Engineer

Kubernetes and GitOps

Introduction to GitOps

GitOps leverages Git as the single source of truth to manage your entire delivery lifecycle—spanning infrastructure definitions, application manifests, automated deployments, and rollbacks. Building on the principles of Infrastructure as Code, GitOps uses Git’s versioning, branching, and pull-request workflows to ensure your production environment always matches what’s declared in your repository.

Why GitOps?

  • Git-Centric Control
    Every change is performed via Git commits and pull requests.
  • Declarative Desired State
    Infrastructure and applications are described in code, making the system reproducible.
  • Automated Reconciliation
    A GitOps operator constantly syncs the live cluster state with the Git repository.

The image illustrates a GitOps workflow, showing the integration of infrastructure, configuration, and application code into a Git repository, followed by continuous integration (CI) and continuous deployment (CD) processes to a Kubernetes cluster. It also depicts a branching and merging process with version control.

  1. Declarative Configuration
    Store all infrastructure, application manifests, and configuration files in Git.
  2. Versioned and Immutable
    Every change is tracked. Roll back by reverting to a previous commit.
  3. Automated Delivery Pipeline
    A GitOps operator inside your Kubernetes cluster watches Git for updates.
  4. Continuous Reconciliation
    Drift detection ensures the live environment matches the desired state.

Developer Workflow

  1. Create a feature branch from main.
  2. Update application code or Kubernetes manifests.
  3. Open a pull request for review.
  4. After approval, merge back into the central repository.

CI/CD Integration

A CI system automatically:

  • Runs unit and integration tests.
  • Builds a Docker image and pushes it to a container registry.
  • Updates the Kubernetes manifests in your Git repository.

The image illustrates a GitOps workflow, showing the process from application code merging to continuous integration, and synchronization of Kubernetes manifests to achieve the desired state in production environments.

GitOps Operator Workflow

  1. The operator polls (or listens for webhooks) on your Git repository.
  2. Detects changes in manifests or configs.
  3. Applies updates to your Kubernetes cluster (or clusters).
  4. Continuously monitors live state and reconciles any drift.

The image illustrates a GitOps workflow, showing the process from application code merging and continuous integration to Kubernetes manifest synchronization and deployment, highlighting desired and actual states.

ComponentPurposeExample Tool
Git RepositorySingle source of truth for code and configsGitHub, GitLab
GitOps OperatorSyncs Git state to the clusterArgo CD, Flux
CI SystemBuilds, tests, and packages applicationsJenkins, GitHub Actions
Container RegistryStores Docker imagesDocker Hub, ECR
Kubernetes ClusterRuns and orchestrates workloadsEKS, GKE, AKS

Since all changes are versioned, reverting is as simple as:

git revert <commit-hash>

The GitOps operator will detect the revert, pull the previous desired state, and roll back your cluster.

Note

GitOps operators typically reconcile every few seconds. If you manually change resources in your cluster, the operator will revert them to match the Git state.

Watch Video

Watch video content

Previous
Brief Overview on Kubernetes