Argo CD 应用程序


Red Hat OpenShift GitOps 1.9

使用 Argo CD 仪表板或 oc 工具在 OpenShift 集群中创建并部署应用程序

Red Hat OpenShift Documentation Team

摘要

本文档提供有关使用 Argo CD 仪表板或使用 oc 工具将应用程序创建和部署到 OpenShift 集群的说明。它还讨论如何在 Argo CD 中验证自我修复行为。

第 1 章 使用 Argo CD 部署 Spring Boot 应用程序

通过 Argo CD,您可以使用 Argo CD 仪表板或使用 oc 工具将应用程序部署到 OpenShift 集群。

1.1. 先决条件

  • 在集群中安装了 Red Hat OpenShift GitOps。
  • 登录到 Argo CD 实例。

1.2. 使用 Argo CD 仪表板创建应用程序

Argo CD 提供了一个仪表板,供您创建应用程序。

流程

  1. 在 Argo CD 控制面板中,单击 NEW APP 以添加新 Argo CD 应用。
  2. 对于此工作流,使用以下配置创建一个 spring-petclinic 应用程序:

    应用程序名称
    spring-petclinic
    project
    default
    同步策略
    自动
    仓库 URL
    https://github.com/redhat-developer/openshift-gitops-getting-started
    修订
    HEAD
    路径
    app
    目的地
    https://kubernetes.default.svc
    命名空间
    spring-petclinic
  3. 单击 CREATE 以创建应用程序。
  4. 打开 Web 控制台的 Administrator 视角,并导航到左侧菜单中的 AdministrationNamespaces
  5. 搜索并选择命名空间,然后在 Label 字段中输入 argocd.argoproj.io/managed-by=openshift-gitops,以便 openshift-gitops 命名空间中的 Argo CD 实例可以管理您的命名空间。

1.3. 使用 oc 工具创建应用程序

您可以使用 oc 工具在终端中创建 Argo CD 应用程序。

流程

  1. 下载 示例应用程序

    $ git clone git@github.com:redhat-developer/openshift-gitops-getting-started.git
    Copy to Clipboard Toggle word wrap
  2. 创建应用程序:

    $ oc create -f openshift-gitops-getting-started/argo/app.yaml
    Copy to Clipboard Toggle word wrap
  3. 运行 oc get 命令以查看所创建的应用程序:

    $ oc get application -n openshift-gitops
    Copy to Clipboard Toggle word wrap
  4. 在部署应用程序的命名空间中添加标签,以便 openshift-gitops 命名空间中的 Argo CD 实例可以管理它:

    $ oc label namespace spring-petclinic argocd.argoproj.io/managed-by=openshift-gitops
    Copy to Clipboard Toggle word wrap

1.4. 验证 Argo CD 自助行为

Argo CD 持续监控已部署应用程序的状态,检测 Git 中指定清单和集群中的实时更改之间的差别,然后自动更正它们。这个行为被称为自我管理。

您可以在 Argo CD 中测试并观察自我管理的行为。

先决条件

  • 已部署并配置 app-spring-petclinic 应用程序示例。

流程

  1. 在 Argo CD 仪表板中,验证您的应用程序是否具有 Synced 状态。
  2. 点 Argo CD 仪表板中的 app-spring-petclinic 标题,查看部署到集群中的应用程序资源。
  3. 在 OpenShift Container Platform web 控制台中进入 Developer 视角。
  4. 修改 Spring PetClinic 部署,并将更改提交到 Git 仓库的 app/ 目录。Argo CD 将自动将更改部署到集群。

    1. Fork OpenShift GitOps getting started repository
    2. deployment.yaml 文件中,将 failureThreshold 值改为 5
    3. 在部署集群中,运行以下命令验证 failureThreshold 字段更改的值:

      $ oc edit deployment spring-petclinic -n spring-petclinic
      Copy to Clipboard Toggle word wrap
  5. 通过修改集群上的部署并扩展到两个容器集来测试自我修复行为,同时在 OpenShift Container Platform Web 控制台中观察应用程序。

    1. 运行以下命令修改部署:

      $ oc scale deployment spring-petclinic --replicas 2  -n spring-petclinic
      Copy to Clipboard Toggle word wrap
    2. 在 OpenShift Container Platform Web 控制台中,请注意部署最多扩展两个 pod,并立即缩减到一个 pod。Argo CD 检测到与 Git 存储库的区别,并在 OpenShift Container Platform 集群中自动修复应用程序。
  6. 在 Argo CD 仪表板中,点 app-spring-petclinic 标题 → APP DETAILSEVENTSEVENTS 选项卡显示以下事件: Argo CD 检测集群中缺少同步部署资源,然后重新同步 Git 存储库进行更正。

法律通告

Copyright © 2024 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat