GitOps 是什么?本文记录一下对于 GitOps 的初步学习。
参考官网:
Pioneered in 2017, GitOps is a way to do Kubernetes cluster management and application delivery. GitOps works by using Git as a single source of truth for declarative infrastructure and applications. With GitOps, the use of software agents can alert on any divergence between Git with what’s running in a cluster, and if there’s a difference, Kubernetes reconcilers automatically update or rollback the cluster depending on the case. With Git at the center of your delivery pipelines, developers use familiar tools to make pull requests to accelerate and simplify both application deployments and operations tasks to Kubernetes.
GitOps 是一种做 K8s 集群管理和应用程序交付的方法。它使用 Git 作为声明式的基层建筑和应用程序的唯一的事实之源。
这里的声明式(declarative)的意思有一些令人费解,经过了反复的阅读,理解到的内容大概是这样,以前对于环境的管理和代码的部署,都是通过一些指令(instruction)来完成,运维通过编写脚本,来执行这些指令,完成这项工作。例如,服务部署在远程服务器上,运维使用远程工具,通过 SSH 通道,把程序推到远程服务器上,然后远程拉起,检查启动情况,之前使用过的工具有 Python 的 Fabric、Eclipse 里面的 ssh 插件、Ansible 等等。
而 GitOps 对此进行了一个突破性的设计(其实仔细思考,这个设计是基于 K8s 的声明式的特性和 Docker 镜像的启动特点),把这些指令变成了一些程序加上代码,这里的程序就例如上文所指的 agent 和 reconciler,代码呢,则是一些配置,保存在 Git 仓库中,这样运维人员只需要去维护这套代码,就达到了对于 K8s 的管理和对于应用程序的交付的工作。
这里的声明式的基础建筑例如 K8s,K8s 完成一个部署是使用下面的语句:
kubectl apply -f *.yaml
而配置文件的内容则是像这样:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
主要内容则是一个 docker 镜像。
而事实之源的意思是使用 Git 来保存所有的配置文件,这样,在搭好了环境之后,所有的工作其实就是对于 Git 仓库里面的文件的修改了。
参考https://aws.amazon.com/cn/blogs/china/build-ci-cd-pipeline-in-gitops-on-aws-china-eks/
https://www.weave.works/technologies/gitops/



