前置: 一套kubernetes集群

一、服务部署

根据自身要求进行部署不同版本

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

HA高可用版本

  1. $ kubectl create namespace argocd
  2. $ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.0.4/manifests/ha/install.yaml

查看部署详情,此步骤由于镜像的原因会很慢

  1. $ kubectl get pods -n argocd
  2. argocd-application-controller-0 1/1 Running 0 15h
  3. argocd-applicationset-controller-66689cbf4b-s6f8z 1/1 Running 0 15h
  4. argocd-dex-server-5b5cf6d675-6xvpp 1/1 Running 0 15h
  5. argocd-notifications-controller-6f498fc8c6-2htbz 1/1 Running 0 15h
  6. argocd-redis-d486999b7-pfb47 1/1 Running 0 15h
  7. argocd-repo-server-5b6f6b7cc-x652q 1/1 Running 0 15h
  8. argocd-server-6d988d7467-thfj6 1/1 Running 0 15h

安装argocd cli

  1. # 这里需要注意版本要和argocd-server版本一致 $VERSION
  2. $ curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
  3. $ chmox +x /usr/local/bin/argocd
  4. $ argocd version
  5. argocd: v2.3.2+ecc2af9
  6. BuildDate: 2022-03-23T02:04:18Z
  7. GitCommit: ecc2af9dcaa12975e654cde8cbbeaffbb315f75c
  8. GitTreeState: clean
  9. GoVersion: go1.17.6
  10. Compiler: gc
  11. Platform: linux/amd64
  12. argocd-server: v2.3.2+ecc2af9
  13. BuildDate: 2022-03-23T00:40:57Z
  14. GitCommit: ecc2af9dcaa12975e654cde8cbbeaffbb315f75c
  15. GitTreeState: clean
  16. GoVersion: go1.17.6
  17. Compiler: gc
  18. Platform: linux/amd64
  19. Ksonnet Version: v0.13.1
  20. Kustomize Version: v4.4.1 2021-11-11T23:36:27Z
  21. Helm Version: v3.8.0+gd141386
  22. Kubectl Version: v0.23.1
  23. Jsonnet Version: v0.18.0

登录argocd ui

  1. # 密码获取
  2. $ kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo
  3. # 更改密码 这里只填argo server的地址 并且svc使用nodePort方式暴露
  4. $ argocd login 10.2.240.31:30619
  5. WARNING: server certificate had error: x509: certificate is valid for e2d1e856c987c94f3c918276921a61ba.6a98e1283291d1b7a23d19e240b6ee89.traefik.default, not argocd.k8s.local. Proceed insecurely (y/n)? y
  6. Username: admin
  7. Password:
  8. 'admin:login' logged in successfully
  9. Context 'argocd.k8s.local' updated
  10. CLI 登录成功后,可以使用如下所示命令更改密码:
  11. $ argocd account update-password
  12. *** Enter current password:
  13. *** Enter new password:
  14. *** Confirm new password:
  15. Password updated
  16. Context 'argocd.k8s.local' updated

二、集群配置

由于 Argo CD 支持部署应用到多集群,所以如果你要将应用部署到外部集群的时候,需要先将外部集群的认证信息注册到 Argo CD 中,如果是在内部部署(运行 Argo CD 的同一个集群,默认不需要配置),应该使用 https://kubernetes.default.svc 作为应用的 K8S APIServer 地址。

首先列出当前 kubeconfig 中的所有集群上下文:

  1. $ kubectl config get-contexts -o name
  2. cnych-context
  3. kubernetes-admin@cluster.local

从列表中选择一个上下文名称并将其提供给 argocd cluster add CONTEXTNAME

  1. $ argocd cluster add kubernetes-admin@cluster.local
  2. # 报错
  3. [root@k8s-master01 argocd]# argocd cluster add kubernetes-admin@cluster.local
  4. WARNING: This will create a service account `argocd-manager` on the cluster referenced by context `kubernetes-admin@cluster.local` with full cluster level admin privileges. Do you want to continue [y/N]? y
  5. INFO[0002] ServiceAccount "argocd-manager" already exists in namespace "kube-system"
  6. INFO[0002] ClusterRole "argocd-manager-role" updated
  7. INFO[0002] ClusterRoleBinding "argocd-manager-role-binding" updated
  8. FATA[0002] rpc error: code = Unknown desc = Get "https://127.0.0.1:6443/version?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
  9. # 解决: https://github.com/argoproj/argo-cd/issues/4204
  10. # 在集群的.kubu/config 配置文件中修改api server地址为真实节点地址,而不是127.0.0.1
  11. $ argocd cluster add kubernetes-admin@cluster.local
  12. WARNING: This will create a service account `argocd-manager` on the cluster referenced by context `kubernetes-admin@cluster.local` with full cluster level admin privileges. Do you want to continue [y/N]? y
  13. INFO[0002] ServiceAccount "argocd-manager" already exists in namespace "kube-system"
  14. INFO[0002] ClusterRole "argocd-manager-role" updated
  15. INFO[0002] ClusterRoleBinding "argocd-manager-role-binding" updated
  16. Cluster 'https://10.2.240.30:6443' added

三、部署测试

3.1 Argocd 指令进行部署测试

  1. $ argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

3.2通过UI进行创建