Argo cli 用法
安装
https://argo-cd.readthedocs.io/en/stable/cli_installation/
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
授权
添加用户权限
以 admin 为例,新增 apiKey 权限
apiVersion: v1
data:
accounts.admin: apiKey, login
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/name: argocd-cm
app.kubernetes.io/part-of: argocd
name: argocd-cm
namespace: argocd
生成 token
argocd account generate-token --account admin
这样每个命令都可以用如下格式使用
argocd app list --auth-token xxx --server argocd-server.argocd.svc.cluster.local --insecure
配置 token
上述每次都要携带参数太麻烦,可以把 token 填写到配置文件中
- 确保配置文件正确设置:
- 确保你的
~/.config/argocd/config文件中包含正确的auth-token字段。例如:
contexts:
- name: default
server: https://argocd.example.com
user: admin
current-context: default
users:
- name: admin
server: https://argocd.example.com
auth-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
然后使用 argo 命令就可以采用 token 登录了,适合 cicd 使用
集群管理
添加集群
argocd cluster add my-cluster-context
如果需要指定特定的 kubeconfig 文件,可以通过 --kubeconfig 参数
argocd cluster add my-cluster-context --kubeconfig path/to/extra-kubeconfig.yaml
查看集群列表
argocd cluster list
修改集群名字和命名空间范围
默认的名字是 context 的名字,这个名字可能会不够直观,我们可以通过 set 命令进一步修改名字
同时可以通过—namespace 指定集群可用的命名空间
argocd cluster set cls-rnibyt9z-100040427493-context-default --name app-prod --namespace '*'
或者添加命名空间 A 和 B
argocd cluster argocd cluster set cls-rnibyt9z-100040427493-context-default --name app-prod --namespace 'A' --namespace 'B'