安装argo cd
1 2
| kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
|
配置ingress暴露argocd ui
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| piVersion: networking.k8s.io/v1 kind: Ingress metadata: name: argocd-server-ingress namespace: argocd annotations: kubernetes.io/ingress.class: nginx nginx.io/tls-acme: "true" nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" nginx.ingress.kubernetes.io/force-ssl-redirect: "true" nginx.ingress.kubernetes.io/ssl-passthrough: "true" spec: rules: - host: argocd.xxx.top http: paths: - path: / pathType: Prefix backend: service: name: argocd-server port: name: https tls: - hosts: - argocd.xxx.top secretName: wildcard-letsencrypt-tls
|
获取agrocd管理员密码
账号admin
1
| kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
|
获取context地址
1
| kubectl config view -o jsonpath='{.current-context}'
|
测试项目运行
编写application.yaml文件,替换repoURL
为仓库地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: myapp-argo-application namespace: argocd spec: project: default
source: repoURL: https://github.com/xxx/argocd-lab.git targetRevision: HEAD path: dev destination: server: https://kubernetes.default.svc namespace: default
syncPolicy: syncOptions: - CreateNamespace=true
automated: selfHeal: true prune: true
|
运行以下命令,在argocd ui界面即可查看到项目情况,argo默认每3分钟同步git仓库与本地部署状态
1
| kubectl apply -f application.yaml
|
配置webhook立马更新
以github为例
- 打开github项目设置页
- 配置项目webhook地址
- 配置webhook secret
webhook url格式
https://argocd.example.com/api/webhook
, url结尾必须为/api/webhook
webhook secret
和下方secret配置保持一致
创建webhook secret
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| apiVersion: v1 kind: Secret metadata: name: argocd-secret namespace: argocd type: Opaque data: ...
stringData: webhook.github.secret: shhhh! it's a GitHub secret
webhook.gitlab.secret: shhhh! it's a GitLab secret
webhook.bitbucket.uuid: your-bitbucket-uuid
webhook.bitbucketserver.secret: shhhh! it's a Bitbucket server secret
webhook.gogs.secret: shhhh! it's a gogs server secret
|
运行以下命令创建secret
1
| kubectl apply -f secret.yaml
|