SRE & AI Field Notes

GitOps Workflow Best Practices for Kubernetes Cluster Management

· Updated 2026-07-26 ⏱️ Reading time 2 min (331 words) GitOps Kubernetes CI/CD

Explore GitOps best practices for Kubernetes cluster management, using ArgoCD to achieve declarative deployment and automated rollback, improving release efficiency and operational stability.

1. GitOps Overview

GitOps is an operational model that uses a Git repository as the single source of truth, leveraging declarative configuration and automated sync mechanisms to ensure that the cluster state always matches the desired state in the repository. In Kubernetes environments, GitOps has become the de facto standard for managing multi-cluster, multi-environment deployments.

2. ArgoCD Best Practices

Using ApplicationSet for multi-cluster deployment management is recommended, combined with Kustomize for environment-specific configuration differentiation. ArgoCD’s automated sync, self-healing, and drift detection capabilities significantly reduce operational overhead.

ArgoCD Application YAML

yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: production-app
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/team/config-repo.git
    targetRevision: main
    path: overlays/production
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

CI/CD Shell Script

bash
#!/bin/bash
# GitOps CI/CD Pipeline
set -euo pipefail

REPO_URL="https://github.com/team/app-repo.git"
CONFIG_REPO="https://github.com/team/config-repo.git"
COMMIT_SHA="${CI_COMMIT_SHA:?commit sha required}"

# Build image
docker build -t app:"${COMMIT_SHA}" .

# Push image
docker tag app:"${COMMIT_SHA}" registry.example.com/app:"${COMMIT_SHA}"
docker push registry.example.com/app:"${COMMIT_SHA}"

# Update image version in config repo
git clone "${CONFIG_REPO}" config-tmp
cd config-tmp
sed -i "s|image: app:.*|image: registry.example.com/app:${COMMIT_SHA}|" overlays/production/deployment.yaml
git add -A
git commit -m "chore: bump app image to ${COMMIT_SHA}"
git push origin main

3. Summary

GitOps brings deployment configurations under version control, enabling auditable and revertible release processes. Combined with the automation capabilities of tools like ArgoCD, teams can increase deployment frequency multiple times over while reducing the risk of human error.

Author:技术领航员 | License:CC BY-NC-SA 4.0

Article Link:https://sre-ai-blog.pages.dev/en/posts/gitops-workflow/(Please credit the source when reposting)