1.8. 使用 GitOps CLI 以核心模式创建应用程序
您可以使用 GitOps argocd CLI 在 core 模式中创建应用程序。
此示例工作流逐步指导您完成将 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。
流程
使用
ocCLI 工具登录到 OpenShift Container Platform 集群:$ oc login -u <username> -p <password> <server_url>Example
$ oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443检查
kubeconfig文件中是否正确设置了上下文:$ oc config current-context将当前上下文的默认命名空间设置为
openshift-gitops:$ oc config set-context --current --namespace openshift-gitops设置以下环境变量来覆盖 Argo CD 组件名称:
$ export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server通过列出所有应用程序,验证您是否可以在
core模式下运行argocd命令:$ argocd app list --core如果配置正确,则现有应用程序将使用以下标头列出:
输出示例
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET以
core模式创建应用程序:$ argocd app create app-cluster-configs --core \ --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 --core虽然
cluster-configsArgo CD 应用程序具有Healthy状态,但它不会因为没有同步策略而自动同步,从而导致它处于OutOfSync状态。