1.7. 使用 GitOps CLI 在默认模式中创建应用程序
您可以使用 GitOps argocd CLI 在默认模式中创建应用程序。
此示例工作流逐步指导您完成将 Argo CD 配置为递归将 cluster 目录中的内容同步到 cluster-configs- 应用程序。目录定义 OpenShift Container Platform 集群配置和集群中的 spring-petclinic 命名空间。
先决条件
- 您已在 OpenShift Container Platform 集群中安装了 Red Hat OpenShift GitOps Operator。
-
已安装 OpenShift CLI(
oc)。 -
已安装 Red Hat OpenShift GitOps
argocdCLI。 - 已登陆到 Argo CD 实例。
流程
获取 Argo CD 服务器的
admin帐户密码:$ ADMIN_PASSWD=$(oc get secret openshift-gitops-cluster -n openshift-gitops -o jsonpath='{.data.admin\.password}' | base64 -d)获取 Argo CD 服务器 URL:
$ SERVER_URL=$(oc get routes openshift-gitops-server -n openshift-gitops -o jsonpath='{.status.ingress[0].host}')使用
admin帐户密码并用单引号括起来来登录到 Argo CD 服务器:重要用单引号括起密码可确保 shell 不会误解特殊字符,如
$。始终使用单引号括起密码的字面值。$ argocd login --username admin --password ${ADMIN_PASSWD} ${SERVER_URL}Example
$ argocd login --username admin --password '<password>' openshift-gitops.openshift-gitops.apps-crc.testing通过列出所有应用程序,验证您是否可以在默认模式下运行
argocd命令:$ argocd app list如果配置正确,则现有应用程序将使用以下标头列出:
输出示例
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET以默认模式创建应用程序:
$ argocd app create app-cluster-configs \ --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git \ --path cluster \ --revision main \ --dest-server https://kubernetes.default.svc \ --dest-namespace spring-petclinic \ --directory-recurse \ --sync-policy none \ --sync-option Prune=true \ --sync-option CreateNamespace=true标记
spring-petclinic目标命名空间,使其由openshif-gitopsArgo CD 实例管理:$ oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"列出可用的应用程序,以确认应用程序是否已成功创建:
$ argocd app list虽然
cluster-configsArgo CD 应用程序具有Healthy状态,但它不会因为没有同步策略而自动同步,从而导致它处于OutOfSync状态。