本文发布于Cylon的收藏册,转载请著名原文链接~

登录argo cd

1
argocd login argocd_server:argocd_port_here

执行后输入admin/sercert

1
2
3
4
5
6
$ argocd login 10.0.0.5:30908
WARNING: server certificate had error: x509: cannot validate certificate for 10.0.0.5 because it doesn't contain any IP SANs. Proceed insecurely (y/n)? y
Username: admin
Password: 
'admin:login' logged in successfully
Context '10.0.0.5:30908' updated

argocd cli 登录后的文件保存在 ~/.argocd/config

注册一个新集群

argocd 通过 kubectl 来获取集群的信息,所以 argocd 的主机上必须有 kubeconfig 文件

Note: KUBECONFIG 文件地址必须为实际路径,比如 ~/ 这种方式不可以

1
export KUBECONFIG="/root/admin.conf"

从 kubeconfig 中提取当前集群的上下文名称

1
kubectl config get-contexts -o name

向 argo 添加 kubernetes 集群

1
2
3
4
5
$ argocd cluster add k8s-admin@kubernetes
INFO[0000] ServiceAccount "argocd-manager" created in namespace "kube-system" 
INFO[0000] ClusterRole "argocd-manager-role" created    
INFO[0000] ClusterRoleBinding "argocd-manager-role-binding" created 
Cluster 'https://10.0.0.4:6443' added

现在可以执行 argocd 命令来列出 argo 中的所有集群,这是为了验证 argocd-cluster 是否已成功添加

1
2
3
4
$ argocd cluster list
SERVER                          NAME                  VERSION  STATUS   MESSAGE
https://10.0.0.4:6443           k8s-admin@kubernetes           Unknown  Cluster has no application and not being monitored.
https://kubernetes.default.svc  in-cluster                     Unknown  Cluster has no application and not being monitored.

删除一个集群

命令 argocd cluster rm 用于从 argo server 中移除一个集群,例如

1
2
argocd cluster rm https://12.34.567.89
argocd cluster rm cluster-name

需要注意的是 in-cluster 集群是 argo 运行的集群,不能够被删除,如果不使用这个集群,需要修改配置 cluster.inClusterEnabled

1
2
# cluster.inClusterEnabled indicates whether to allow in-cluster server address. This is enabled by default.
cluster.inClusterEnabled: "true"

这个配置是在 argocd-cm 中保存的,可以在对应的 configMap 中添加,完整的 argocd 配置见附录1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
kubectl get cm argocd-cm -o yaml
apiVersion: v1
data:
  cluster.inClusterEnabled: "false"
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/name: argocd-cm
    app.kubernetes.io/part-of: argocd
  name: argocd-cm
  namespace: default

Reference

[1] docs/operator-manual/argocd-cm.yaml

[2] Getting started with multi-cluster K8S deployments using Argo CD

本文发布于Cylon的收藏册,转载请著名原文链接~

链接:https://www.oomkill.com/2023/11/ch03-argo-add-cluster/

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」 许可协议进行许可。