Argo CD

背景

Argo CD 是用于 Kubernetes 的声明性 GitOps(git based opreation) 连续交付工具。无论是提交代码还是做生产系统变更的时候都希望通过GitHub来保存变更的内容。

每当GitHub有pr的时候都希望能够自动的部署到环境中,而不是通过手动去操作变更,因为直接到变更是不可追溯的。

使用GitOps,所有的变更都需要通过GitHub或者Gitlab来驱动。变更有一份原始记录,可以追溯。

tekton更多的作为CI工具,tekton + argocd是现在更流行的CI/CD选择。

为什么选择 Argo CD?

  • 应用程序定义,配置和环境应为声明性的,并受版本控制。
  • 应用程序部署和生命周期管理是自动化的,可审核的且易于理解的。
  • 集群状态容易恢复。

架构

  • Argo CD 被实现为 Kubernetes 控制器,该控制器连续监视正在运行的应用程序,并将当前的活动状态与所需的目标状态(在 Git 存储库中指定)进行比较。
  • 其活动状态偏离目标状态的已部署应用程序被标记为OutofSync。
  • Argo CD 报告并可视化差异,同时提供了自动或手动将实时状态同步回所需目标状态的功能。
  • 在Git 存储库中对所需目标状态所做的任何修改都可以自动应用并反映在指定的目标环境中。

file

部署

官方安装

release地址:https://github.com/argoproj/argo-cd/releases

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.3.3/manifests/install.yaml

使用helm安装

helm search repo argo
helm install argocd bitnami/argo-cd -n argocd

file

我这里使用helm安装了,yaml文件下载不下来。。。

file

查看部署情况

k get po -n argocd
# 发现redis pod一直处于pending状态,报错需要pvc。。。

file

下载repo

helm pull bitnami/argo-cd
tar xvf argo-cd-3.1.12.tgz

修改value.yaml中storageClass

global:
  imageRegistry: ""
  imagePullSecrets: []
  storageClass: "nfs-client"
helm install argocd . -n argocd

file

这里仍然报错需要pvc

k get pvc -n argocd
# 删除上次部署的pending状态pvc
k delete pvc redis-data-argocd-redis-master-0 -n argocd
k get po -n argocd
k delete po argocd-redis-master-0 -n argocd
# 删除pod,让pvc自动创建
k get po -n argocd

file

查看部署情况

k get po,svc -n argocd

file

设置ingress

cat argocd-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-ingress
  namespace: argocd
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: letsencrypt-pro
    # 我这里就没加https和下面的tls,换了好几个浏览器都是307。。。
    # If you encounter a redirect loop or are getting a 307 response code
    # then you need to force the nginx ingress to connect to the backend using HTTPS.
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
  ingressClassName: nginx
  rules:
  - host: argocd.xxx
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: argocd-argo-cd-server
            port:
              number: 80
  tls:
  - hosts:
    - argocd.xxx
    secretName: argocd-secret # do not change, this is provided by Argo CD

file

访问 argocd 控制台

https://argocd.xxx

用户名:admin
密码:kubectl -n argocd get secret argocd-secret -o jsonpath="{.data.clearPassword}" | base64 -d

file

实践

  1. 登录gitee或者GitHub,gittlab。创建仓库,文件夹。格式如下:(必须创建文件夹)
    file

  2. 登录argocd,设置->Repository->Connect repo using HTTPS->填写Repository URL
    file
    file

  3. create application->填写Application Name->选择Project->填写资源路径->选择Cluster URL->填写Namespace
    file
    file

  4. 创建成功后,app状态为OutOfSync,因为还没有同步。
    file

  5. 点击myapp,再点击sync,synchronize。查看状态为Synced。应用已经完成了部署。
    file
    file

  6. 查看pod。
    file

  7. 修改deployment中的镜像版本为不存在的版本。
    file
    可以从页面上看到有一个rev:2被创建出来了,pod状态为ErrImagePull。
    file

  8. 再次点击sync。已经恢复到上次的状态了。
    file

适用场景

  1. 低成本的 GitOps 利器
  2. 多集群管理
    不同目的集群:测试,集成,预生产,生产
    多生产集群管理
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部
0
希望看到您的想法,请您发表评论x