【GitOps】Argo CD自动同步Push请求
Argo CD自动同步Push请求
文章目录
- Argo CD自动同步Push请求
- 资源列表
- 一、创建Gitlba仓库
- 1.1、创建仓库
- 1.2、编写资源清单
- 二、创建Application
- 三、设置GitLab的Webhook
- 3.1、设置Web Hook
- 3.2、配置Argo CD Secret
- 3.3、配置Web Hook
- 3.4、测试webhook
- 3.5、更改仓库yaml字段
资源列表
操作系统 | 配置 | 主机名 | IP | 所需软件 |
---|---|---|---|---|
CentOS 7.9 | 2C4G | master | 192.168.93.145 | Docker Ce、kube-apiserver、kube-controller-manager、kube-scheduler、kubelet、Etcd、kube-proxy |
CentOS 7.9 | 2C4G | node1 | 192.168.93.146 | Docker CE、kubectl、kube-proxy、Flnnel |
CentOS 7.9 | 2C4G | node2 | 192.168.93.147 | Docker CE、kubectl、kube-proxy、Flnnel |
CentOS 7.9 | 2C4G | gitlab | 192.168.93.102 | GtiLab |
一、创建Gitlba仓库
- 创建的仓库是用来存放
Kubernetes
的资源清单
1.1、创建仓库
1.2、编写资源清单
[root@gitlab ~]# git clone http://192.168.93.102/root/argocd-test.git
[root@gitlab ~]# cd argocd-test/
# 准备所需资源(测试)
[root@gitlab argocd-test]# cat deployment.yaml
apiVersion: "apps/v1"
kind: Deployment
metadata:name: argocd-deploymentlabels:app: argocd
spec:replicas: 3selector:matchLabels:app: argocdtemplate:metadata:labels:app: argocdspec:containers:- name: nginximage: nginx:latestimagePullPolicy: IfNotPresentports:- containerPort: 80[root@gitlab argocd-test]# cat service.yaml
apiVersion: "v1"
kind: Service
metadata:name: argocd-nginxlabels:app: argocd
spec:selector:app: argocdtype: NodePortports:- port: 80protocol: TCPtargetPort: 80nodePort: 30007
# 提交代码至仓库中
[root@gitlab argocd-test]# git add .
[root@gitlab argocd-test]# git commit -m "v1"
[root@gitlab argocd-test]# git push -u origin
二、创建Application
- 仓库Argo CD资源
三、设置GitLab的Webhook
- 设置触发Push请求
3.1、设置Web Hook
3.2、配置Argo CD Secret
[root@master ~]# kubectl edit secret -n argocd argocd-secret
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
stringData:# gitlab webhook secretwebhook.gitlab.secret: wzh
3.3、配置Web Hook
# 调用的Argo CD是域名所以要在 gitlab 主机做hosts解析
[root@gitlab argocd-test]# cat /etc/hosts | tail -1
192.168.93.146 argocd.devops-engineer.com.cn
- URL填写Argo CD API接口:
https://argocd.devops-engineer.com.cn/api/webhook
- Secret Token:填写上面加入的数字
123
- Trigger:
提交到什么分支会发送push请求(main)
3.4、测试webhook
# 提前监控 Argo CD服务是否有接收push请求(添加上面hook确定之后)
[root@master ~]# kubectl logs -f -n argocd argocd-server-b6b977d99-4kp5r
time="2024-12-22T03:30:44Z" level=info msg="Received push event repo: http://192.168.93.102/root/argocd-test, revision: main, touchedHead: true"
time="2024-12-22T03:30:44Z" level=info msg="Requested app 'argocd-push' refresh"
3.5、更改仓库yaml字段
-
更改
image
镜像,然后快速回到Argo CD即可看到效果
-
点击其中一个即可