--- title: "CTP Topic 33 An Introduction to GitOps" type: source tags: - GitOps - CI/CD - Kubernetes - DevOps - Infrastructure as Code date: 2026-04-14 --- ## Source File - [[Cloud & DevOps/Public-Cloud-Learning-Sessions/06_CI_CD_GitOps/ctp-topic-33-an-introduction-to-gitops.md]] ## Summary(用中文描述) - 核心主题:GitOps 方法论入门——将软件开发原则应用于部署流程,实现声明式基础设施自动化交付 - 问题域:解决部署失败、配置不一致、手动操作风险等传统 CI/CD 问题 - 方法/机制:四大原则(声明式配置 + 版本控制 + CD 流程分离 + 自修复协调器)+ Pull/Push 两种部署模型 - 结论/价值:开发者只需掌握 Git 即可完成安全部署,代码变更分钟级上线,Git 日志即审计追踪 ## Key Claims(用中文描述) - GitOps 四大原则使部署过程完全自动化,代码变更可在数分钟内安全部署上线 - Pull 模型比 Push 模型更适合 GitOps——部署代理同时监控 Git 和目标系统,提供额外安全层 - 幂等(Idempotent)平台(如 Kubernetes)是 CD 流程顺利执行的必要条件 - GitOps 是 DevOps 的逻辑演进,Git 提交日志天然构成合规审计追踪 - CI 与 CD 应解耦——CI 专注构建和分析代码,CD 专注部署二进制文件,解耦增强安全性 ## Key Quotes > "The only tool a developer needs to know is Git." — Victor Etkin > "GitOps uses Git workflows, CD pipelines, and infrastructure as code. Observability is crucial for ensuring the desired and actual states align." > "An IDEMPOTENT operation is one that can be applied multiple times without changing the result beyond the initial application." > "GitOps is a logical evolution of DevOps, simplifying adoption and enhancing portability. Git commit logs become audit trails, streamlining compliance." ## Key Concepts - [[GitOps]]:将软件开发原则(Git 版本控制 + Pull Request 协作)应用于基础设施和应用部署的方法论,核心是通过声明式配置描述期望状态,GitOps 控制器自动协调实际状态向期望状态收敛 - [[Idempotent Deployment(幂等部署)]]:同一操作可重复执行而结果不变的特性,是 GitOps CD 流程顺利运行的必要前提,Kubernetes 是典型的幂等平台 - [[Pull Model]]:GitOps 推荐部署模型——部署代理持续监控 Git 仓库和目标系统状态,检测到差异时自动从 Git 拉取变更并应用,天然提供额外安全层(系统状态不暴露给外部) - [[Push Model]]:CI/CD 管道主动推送变更到目标系统的部署模式,相比 Pull 模型安全性较低但实现更简单 - [[Declarative Configuration(声明式配置)]]:通过代码描述"系统应该是什么状态"而非"如何一步步到达该状态",是 GitOps 和 Infrastructure as Code 的核心原则 - [[Infrastructure as Code(基础设施即代码)]]:用代码管理基础设施的实践,与 GitOps 高度协同,共同构成自动化部署的基础 - [[GitOps Controller]]:运行在目标环境中的自动化代理,持续比对 Git 中声明的期望状态与系统实际状态,自动调和偏差,无需人工干预 ## Key Entities - [[Victor Etkin]]:GitOps 入门视频主讲人,阐述 GitOps 四大原则及 Pull 模型优势 - [[Weaveworks]]:GitOps 概念的提出者和早期推广者(视频背景知识) - [[Kubernetes]]:GitOps 最常用的部署目标平台,其声明式 API 和自修复机制与 GitOps 高度契合 - [[Atlantis]]:基于 Pull Request 的 Terraform IaC 自动化工具(参见 [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]]),属 GitOps 工具实践层 ## Connections - [[ctp-topic-2-git]] ← foundational_skill ← [[GitOps]](Git 版本控制是 GitOps 的基础工具) - [[ctp-topic-9-ci-cd-with-gruntwork]] ← extends ← [[GitOps]](CI/CD 是 GitOps 的核心组件) - [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]] ← implements ← [[GitOps]](Atlantis 是 GitOps 工具实践) - [[GitOps]] ← complements ← [[DevOps]](GitOps 是 DevOps 的逻辑演进) - [[Amazon EKS]] ← platform ← [[GitOps]](K8s 是 GitOps 最常用目标平台) - [[GitOps]] ← extends ← [[Infrastructure as Code]](GitOps 是 IaC 的部署编排层) ## Contradictions - 与 [[ctp-topic-39-implementing-eks-in-the-aws-lab-landing-zone]] 存在实践约束差异: - 冲突点:Atlantis 当前不支持 EKS 部署 - 当前观点(Topic 33):Kubernetes 是 GitOps 的主要应用场景 - 对方观点(Topic 39):Atlantis 需通过 Jenkins + Terragrunt 替代方案处理 EKS 工作负载