安装 GitOps
安装 OpenShift GitOps Operator,登录到 Argo CD 实例并安装 GitOps CLI
摘要
第 1 章 准备安装 Red Hat OpenShift GitOps
在 OpenShift Container Platform 上安装 Red Hat OpenShift GitOps 前,请阅读以下有关大小要求和先决条件的信息。大小要求还为 Red Hat OpenShift GitOps Operator 实例化的默认 ArgoCD 实例提供大小详情。
1.1. GitOps 的大小要求
Red Hat OpenShift GitOps 是为云原生应用程序实施持续部署的一种声明方法。通过 GitOps,您可以定义并配置应用程序的 CPU 和内存要求。
每次安装 Red Hat OpenShift GitOps Operator 时,命名空间上的资源都会在定义的限制中安装。如果默认安装没有设置任何限制或请求,Operator 会使用配额在命名空间中失败。如果没有足够资源,集群无法调度 ArgoCD 相关 pod。下表列出了默认工作负载的资源请求和限值:
Workload | CPU 请求 | CPU 限值 | 内存请求 | 内存限值 |
---|---|---|---|---|
argocd-application-controller | 250m | 2 | 1024Mi | 2048Mi |
applicationset-controller | 250m | 2 | 512Mi | 1024Mi |
argocd-server | 125m | 500m | 128Mi | 256Mi |
argocd-repo-server | 250m | 1 | 256Mi | 1024Mi |
argocd-redis | 250m | 500m | 128Mi | 256Mi |
argocd-dex-server | 250m | 500m | 128Mi | 256Mi |
argocd-redis-ha-haproxy | 200m | 500m | 128Mi | 256Mi |
另外,您还可以在 oc
命令中使用 ArgoCD 自定义资源来查看特定并修改它们:
oc edit argocd <name of argo cd> -n namespace
1.1.1. argocd-redis 的大小要求
在 Red Hat OpenShift GitOps Operator 中应用程序的容量规划阶段,您必须确保为 argocd-redis
pod 分配足够数量的资源,如 memory、CPU 和存储。
Redis pod 的默认内存限值可能不足以管理大量资源。在这些情况下,您必须提高内存限制,监控内存指标,并在应用程序部署扩展时更改内存配置。
以下命令显示 openshift-gitops
命名空间中的 Redis pod 的内存配置示例:
$ oc get argocd -n openshift-gitops openshift-gitops -o json | jq '.spec.redis.resources'
输出示例
{ "limits": { 1 "cpu": "500m", "memory": "256Mi" }, "requests": { 2 "cpu": "250m", "memory": "128Mi" } }
以下示例命令更改 Redis pod 的内存配置。最高资源限值阈值设置为 8 GiB,最低值设为 256 MiB。
$ oc patch argocd -n openshift-gitops openshift-gitops --type json -p '[{"op": "replace", "path": \ "/spec/redis/resources/limits/memory", "value": "8Gi"}, {"op": "replace", "path": \ "/spec/redis/resources/requests/memory", "value": "256Mi"}]'
输出示例
argocd.argoproj.io/openshift-gitops patched
第 2 章 安装 Red Hat OpenShift GitOps
Red Hat OpenShift GitOps 使用 Argo CD 管理特定集群范围的资源,包括:集群 Operator、可选 Operator Lifecycle Manager(OLM)Operator 和用户管理。
2.1. 先决条件
- 访问 OpenShift Container Platform web 控制台。
-
以具有
cluster-admin
角色的用户身份登录。 - 以管理员身份登陆到 OpenShift Container Platform 集群。
- 您的集群启用了 Marketplace 功能,或者手动配置 Red Hat Operator 目录源。
如果您已安装 Argo CD Operator 的 Community 版本,请在安装 Red Hat OpenShift GitOps Operator 前删除 Argo CD Community Operator。
本指南介绍如何将 Red Hat OpenShift GitOps Operator 安装到 OpenShift Container Platform 集群,并登录 Argo CD 实例。
latest
频道启用 Red Hat OpenShift GitOps Operator 最新稳定版本的安装。目前,这是安装 Red Hat OpenShift GitOps Operator 的默认频道。
要安装 Red Hat OpenShift GitOps Operator 的特定版本,集群管理员可以使用对应的 gitops-<version>
频道。例如,要安装 Red Hat OpenShift GitOps Operator 版本 1.8.x,您可以使用 gitops-1.8
频道。
2.2. 在 Web 控制台中安装 Red Hat OpenShift GitOps Operator
您可以使用 Web 控制台从 OperatorHub 安装 Red Hat OpenShift GitOps Operator。
流程
- 打开 Web 控制台的 Administrator 视角,再进入 Operators → OperatorHub。
-
搜索
OpenShift GitOps
,点 Red Hat OpenShift GitOps 标题,然后点 Install。 在 Install Operator 页面中:
- 选择一个 更新频道。
- 选择要安装的 GitOps Version。
选择一个 Installed Namespace。默认安装命名空间是
openshift-gitops-operator
。注意对于 GitOps 版本 1.10 及更新的版本,默认命名空间从
openshift-operators
改为openshift-gitops operator
。选中 Enable Operator recommended cluster monitoring on this Namespace 来启用集群监控。
注意您可以通过应用
openshift.io/cluster-monitoring=true
标签在任意命名空间上启用集群监控:$ oc label namespace <namespace> openshift.io/cluster-monitoring=true
输出示例
namespace/<namespace> labeled
点 Install 使 GitOps Operator 在 OpenShift Container Platform 集群上可用。
Red Hat OpenShift GitOps 安装在集群的所有命名空间中。
- 验证 Red Hat OpenShift GitOps Operator 是否在 Operators → Installed Operators 中列出。Status 应变为 Succeeded。
安装 Red Hat OpenShift GitOps Operator 后,它会自动设置 openshift-gitops
命名空间中的已就绪的 Argo CD 实例,并在控制台工具栏中显示 Argo CD 图标。您可以在项目下为您的应用程序创建后续的 Argo CD 实例。
2.3. 使用 CLI 安装 Red Hat OpenShift GitOps Operator
您可以使用 CLI 从 OperatorHub 安装 Red Hat OpenShift GitOps Operator。
对于 GitOps 版本 1.10 及更新的版本,默认命名空间从 openshift-operators
改为 openshift-gitops operator
。
流程
创建
openshift-gitops-operator
命名空间:$ oc create ns openshift-gitops-operator
输出示例
namespace/openshift-gitops-operator created
注意您可以通过应用
openshift.io/cluster-monitoring=true
标签,在openshift-gitops-operator
或任何命名空间上启用集群监控:$ oc label namespace <namespace> openshift.io/cluster-monitoring=true
输出示例
namespace/<namespace> labeled
创建一个
OperatorGroup
对象 YAML 文件,如gitops-operator-group.yaml
:OperatorGroup 示例
apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: openshift-gitops-operator namespace: openshift-gitops-operator spec: upgradeStrategy: Default
将
OperatorGroup
应用到集群:$ oc apply -f gitops-operator-group.yaml
输出示例
operatorgroup.operators.coreos.com/openshift-gitops-operator created
创建一个
Subscription
对象 YAML 文件,以便为 Red Hat OpenShift GitOps Operator 订阅一个命名空间,如openshift-gitops-sub.yaml
:订阅示例
apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: openshift-gitops-operator namespace: openshift-gitops-operator spec: channel: latest 1 installPlanApproval: Automatic name: openshift-gitops-operator 2 source: redhat-operators 3 sourceNamespace: openshift-marketplace 4
将
订阅
应用到集群:$ oc apply -f openshift-gitops-sub.yaml
输出示例
subscription.operators.coreos.com/openshift-gitops-operator created
安装完成后,验证
openshift-gitops
命名空间中的所有 pod 是否正在运行:$ oc get pods -n openshift-gitops
输出示例
NAME READY STATUS RESTARTS AGE cluster-b5798d6f9-zr576 1/1 Running 0 65m openshift-gitops-application-controller-0 1/1 Running 0 53m openshift-gitops-applicationset-controller-6447b8dfdd-5ckgh 1/1 Running 0 65m openshift-gitops-dex-server-569b498bd9-vf6mr 1/1 Running 0 65m openshift-gitops-redis-74bd8d7d96-49bjf 1/1 Running 0 65m openshift-gitops-repo-server-c999f75d5-l4rsg 1/1 Running 0 65m openshift-gitops-server-5785f7668b-wj57t 1/1 Running 0 53m
验证
openshift-gitops-operator
命名空间中的 pod 是否正在运行:$ oc get pods -n openshift-gitops-operator
输出示例
NAME READY STATUS RESTARTS AGE openshift-gitops-operator-controller-manager-664966d547-vr4vb 2/2 Running 0 65m
2.4. 使用 Argo CD admin 帐户登录到 Argo CD 实例
Red Hat OpenShift GitOps 会自动创建一个可用的 Argo CD 实例,该实例在 openshift-gitops
命名空间中可用。另外,您可以创建一个新的 Argo CD 实例来管理集群配置或部署应用程序。
使用 Argo CD admin 帐户登录到默认的可随时使用 Argo CD 实例或新安装的 Argo CD 实例。
先决条件
- 您已在 OpenShift Container Platform 集群上安装了 Red Hat OpenShift GitOps Operator。
流程
- 在 Web 控制台的 Administrator 视角中,导航到 Operators → Installed Operators,以验证是否安装了 Red Hat OpenShift GitOps Operator。
-
进入
menu → OpenShift GitOps → Cluster Argo CD。Argo CD UI 的登录页面显示在新窗口中。
可选: 要使用 OpenShift Container Platform 凭证登录,请确保您是
cluster-admins
组的用户,然后在 Argo CD 用户界面中选择LOG IN VIA OPENSHIFT
选项。注意要是
cluster-admins
组的用户,请使用oc adm groups new cluster-admins <user&
gt; 命令,其中 <user
> 是您可以在集群范围或本地绑定到用户和组的默认集群角色。获取 Argo CD 实例的密码:
- 使用导航面板进入 Workloads → Secrets 页面。
- 使用 Project 下拉列表并选择创建 Argo CD 实例的命名空间。
- 选择 & lt;argo_CD_instance_name>-cluster 实例来显示密码。
- 在 Details 标签页中,将密码复制到 Data → admin.password 下。
-
使用
admin
作为 Username,复制的密码作为 Password,在新窗口中登录到 Argo CD UI。
您不能在同一命名空间中创建两个 Argo CD CR。
2.5. 其他资源
第 3 章 安装 GitOps CLI
Red Hat OpenShift GitOps argocd
CLI 工具只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。
有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围。
使用 GitOps argocd
CLI 工具从命令行配置和管理 Red Hat OpenShift GitOps 和 Argo CD 资源。GitOps argocd
CLI 旨在使 GitOps 计算任务简单而简洁。您可以在不同的平台中安装 CLI 工具。
压缩的存档和 RPM 都包含 argocd
可执行文件。如果您在红帽帐户中有一个有效的 OpenShift Container Platform 订阅,请使用软件包管理器(如 yum
或 dnf
)将 CLI 工具作为 RPM 安装。
3.1. 在 Linux 上安装 Red Hat OpenShift GitOps CLI
对于 Linux 发行版本,您可以将 GitOps argocd
CLI 下载为 tar.gz
归档。
流程
从您的操作系统和架构 的内容网关 下载最新版本的 CLI 工具。
操作系统 架构 Tarball Linux
x86_64, amd64
argocd-linux-amd64.tar.gz
Linux on IBM zSystems 和 IBM® LinuxONE
s390x
argocd-linux-s390x.tar.gz
Linux on IBM Power
ppc64le
argocd-linux-ppc64le.tar.gz
Linux on ARM
aarch64、arm64
argocd-linux-arm64.tar.gz
注意较新版本的 CLI 工具与旧版本的 Red Hat OpenShift GitOps 服务器兼容,反之亦然。
运行以下命令来提取存档:
$ tar xvzf <file>
运行以下命令,将二进制文件移到
PATH
环境变量的目录中:$ sudo mv argocd /usr/local/bin/argocd
运行以下命令使文件可执行:
$ sudo chmod +x /usr/local/bin/argocd
安装 GitOps
argocd
CLI 后,运行以下命令来验证其是否可用:$ argocd version --client
输出示例
argocd: v2.9.5+f943664 BuildDate: 2024-02-15T05:19:27Z GitCommit: f9436641a616d277ab1f98694e5ce4c986d4ea05 GitTreeState: clean GoVersion: go1.20.10 Compiler: gc Platform: linux/amd64 ExtraBuildInfo: openshift-gitops-version: 1.12.0, release: 0015022024 1
- 1
- 红帽构建的 Red Hat OpenShift GitOps 的构建信息。
3.2. 使用 RPM 在 Linux 上安装 Red Hat OpenShift GitOps CLI
对于 Red Hat Enterprise Linux (RHEL)版本 8 或更高版本,您可以使用软件包管理器(如 yum
或 dnf
)将 GitOps argocd
CLI 安装为 RPM。这允许系统自动管理 GitOps argocd
CLI 版本。例如,如果有新版本可用,使用 dnf upgrade
等命令升级所有软件包,包括 argocd
。
先决条件
- 您的红帽帐户必须具有有效的 OpenShift Container Platform 订阅。
-
在本地系统中具有 root 或
sudo
权限。
流程
运行以下命令,使用 Red Hat Subscription Manager 注册:
# subscription-manager register
运行以下命令来拉取最新的订阅数据:
# subscription-manager refresh
运行以下命令列出可用的订阅:
# subscription-manager list --available --matches '*gitops*'
在上一命令的输出中,找到 OpenShift Container Platform 订阅的池 ID,并运行以下命令来将订阅附加到注册的系统:
# subscription-manager attach --pool=<pool_id>
运行以下命令,为 RHEL 版本 8 或更高版本启用 Red Hat OpenShift GitOps 所需的存储库:
Linux (x86_64, amd64)
# subscription-manager repos --enable="gitops-<gitops_version>-for-rhel-<rhel_version>-x86_64-rpms"
示例命令
# subscription-manager repos --enable="gitops-1.15-for-rhel-8-x86_64-rpms"
Linux on IBM zSystems 和 IBM® LinuxONE (s390x)
# subscription-manager repos --enable="gitops-<gitops_version>-for-rhel-<rhel_version>-s390x-rpms"
示例命令
# subscription-manager repos --enable="gitops-1.15-for-rhel-8-s390x-rpms"
Linux on IBM Power (ppc64le)
# subscription-manager repos --enable="gitops-<gitops_version>-for-rhel-<rhel_version>-ppc64le-rpms"
示例命令
# subscription-manager repos --enable="gitops-1.15-for-rhel-8-ppc64le-rpms"
Linux on ARM (aarch64, arm64)
# subscription-manager repos --enable="gitops-<gitops_version>-for-rhel-<rhel_version>-aarch64-rpms"
示例命令
# subscription-manager repos --enable="gitops-1.15-for-rhel-8-aarch64-rpms"
运行以下命令来安装
openshift-gitops-argocd-cli
软件包:# yum install openshift-gitops-argocd-cli
安装 GitOps
argocd
CLI 后,运行以下命令来验证其是否可用:$ argocd version --client
输出示例
argocd: v2.9.5+f943664 BuildDate: 2024-02-15T05:19:27Z GitCommit: f9436641a616d277ab1f98694e5ce4c986d4ea05 GitTreeState: clean GoVersion: go1.20.10 Compiler: gc Platform: linux/amd64 ExtraBuildInfo: openshift-gitops-version: 1.12.0, release: 0015022024 1
- 1
- 红帽构建的 Red Hat OpenShift GitOps 的构建信息。
3.3. 在 Windows 上安装 Red Hat OpenShift GitOps CLI
对于 Windows,您可以将 GitOps argocd
CLI 下载为压缩 zip
存档。
流程
从您的操作系统和架构 的内容网关 下载最新版本的 CLI 工具。
操作系统 架构 Tarball Windows
x86_64
argocd-windows-amd64.zip
注意较新版本的 CLI 工具与旧版本的 Red Hat OpenShift GitOps 服务器兼容,反之亦然。
- 使用 ZIP 程序解压存档。
运行以下命令,将二进制文件移到
PATH
环境变量的目录中:C:\> move argocd.exe <directory>
安装 GitOps
argocd
CLI 后,运行以下命令来验证其是否可用:$ argocd version --client
输出示例
argocd: v2.9.5+f943664 BuildDate: 2024-02-15T05:19:27Z GitCommit: f9436641a616d277ab1f98694e5ce4c986d4ea05 GitTreeState: clean GoVersion: go1.20.10 Compiler: gc Platform: linux/amd64 ExtraBuildInfo: openshift-gitops-version: 1.12.0, release: 0015022024 1
- 1
- 红帽构建的 Red Hat OpenShift GitOps 的构建信息。
3.4. 在 macOS 上安装 Red Hat OpenShift GitOps CLI
对于 macOS,您可以将 GitOps argocd
CLI 下载为 tar.gz
存档。
流程
从您的操作系统和架构 的内容网关 下载最新版本的 CLI 工具。
操作系统 架构 Tarball Intel 上的 macOS
x86_64
argocd-macos-amd64.tar.gz
macOS on ARM
arm64
argocd-macos-arm64.tar.gz
注意较新版本的 CLI 工具与旧版本的 Red Hat OpenShift GitOps 服务器兼容,反之亦然。
运行以下命令来提取存档:
$ tar xvzf <file>
运行以下命令,将二进制文件移到
PATH
环境变量的目录中:$ sudo mv argocd /usr/local/bin/argocd
运行以下命令使文件可执行:
$ sudo chmod +x /usr/local/bin/argocd
安装 GitOps
argocd
CLI 后,运行以下命令来验证其是否可用:$ argocd version --client
输出示例
argocd: v2.9.5+f943664 BuildDate: 2024-02-15T05:19:27Z GitCommit: f9436641a616d277ab1f98694e5ce4c986d4ea05 GitTreeState: clean GoVersion: go1.20.10 Compiler: gc Platform: linux/amd64 ExtraBuildInfo: openshift-gitops-version: 1.12.0, release: 0015022024 1
- 1
- 红帽构建的 Red Hat OpenShift GitOps 的构建信息。