先决条件:
1.已经有k8s集群,(网上一万种部署方式,这里我使用的是kubekey部署的),也埋了个坑,后面说明.
2.已经部署好argocd,并验证web已经可以访问.参见k8s部署argocd-CSDN博客
部署客户端工具,
这里我是从web页面上直接下载的对应版本的cli工具.
打开已经部署好的argocd的web页面,点击doc,

下载linux(AMD64),这里其实就是从已经部署好的server端下载的argocdcli工具.版本直接是匹配的.
如果不想从这里下载可以从github上下载,地址如下:https://github.com/argoproj/argo-cd/releases/tag/v2.4.2
这里选择下载的二进制包如下,

将下载好的包上传到服务器这里(具体操作步骤省略)
这里我直接上传到了/usr/local/bin/
添加可执行权限
Go
[root@module /usr/local/bin]$chmod +x argocd-linux-amd64
重命名(方便后面使用)
Go
[root@module /usr/local/bin]$mv argocd-linux-amd64 argocd
查看基本信息
Go
[root@module /usr/local/bin]$argocd version
argocd: v2.4.2+c6d0c8b
BuildDate: 2022-06-21T20:42:05Z
GitCommit: c6d0c8baaa291cd68465acd7ad6bef58b2b6f942
GitTreeState: clean
GoVersion: go1.18.3
Compiler: gc
Platform: linux/amd64
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
argocd-server: v2.4.2+c6d0c8b
BuildDate: 2022-06-21T20:42:05Z
GitCommit: c6d0c8baaa291cd68465acd7ad6bef58b2b6f942
GitTreeState: clean
GoVersion: go1.18.3
Compiler: gc
Platform: linux/amd64
Kustomize Version: v4.4.1 2021-11-11T23:36:27Z
Helm Version: v3.8.1+g5cb9af4
Kubectl Version: v0.23.1
Jsonnet Version: v0.18.0
这里表示已经将cli工具部署成功.接下来就是添加k8s集群.
添加k8s集群
说明一下:
这里我因为使用的是kubekey创建的k8s集群,所以在k8s的config文件中的地址无法在argocd中解析出来.导致无法添加成功,将
Go
将/root/.kube/config文件中的server字段修改成master主机的ip地址就可以.

因为个人的环境有所差异,所以这里不做过多解释.
使用cli工具添加k8s集群.
查看集群context的name,
Go
[root@module ~/.kube]$kubectl config get-contexts -o name
[email protected]
#这里的集群名称是
[email protected]
使用cli工具添加集群到argocd中
添加集群到 Argo CD(使用 gRPC Web 模式,也可以不用这个非必选项)
Go
#添加k8s集群到argocd
[root@module ~/.kube]$argocd cluster add [email protected] --kubeconfig ~/.kube/config --grpc-web
WARNING: This will create a service account `argocd-manager` on the cluster referenced by context `[email protected]` with full cluster level privileges. Do you want to continue [y/N]? y
INFO[0003] ServiceAccount "argocd-manager" already exists in namespace "kube-system"
INFO[0003] ClusterRole "argocd-manager-role" updated
INFO[0003] ClusterRoleBinding "argocd-manager-role-binding" updated
Cluster 'https://192.168.59.100:6443' added
查看添加集群结果
Go
[root@module ~/.kube]$argocd cluster list
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
SERVER NAME VERSION STATUS MESSAGE PROJECT
https://192.168.59.100:6443 [email protected] Unknown Cluster has no applications and is not being monitored.
https://kubernetes.default.svc in-cluster Unknown Cluster has no applications and is not being monitored
登陆web页面查看结果
settings-->cluster


验证完成,添加成功