1.8. 使用 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
argocd
CLI。
流程
使用
oc
CLI 工具登录到 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
通过列出所有应用程序,验证您能够在
核心
模式下运行argocd
命令:$ argocd app list --core
如果配置正确,则使用以下标头列出现有应用程序:
输出示例
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
以
核心
模式创建应用程序:$ 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-gitops
Argo CD 实例管理:$ oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
列出可用的应用程序,以确认应用程序已创建成功:
$ argocd app list --core
虽然
cluster-configs
Argo CD 应用程序具有Healthy
状态,但它不会因为没有
同步策略而自动同步,从而导致它保留在OutOfSync
状态。