第 6 章 Quay Operator 功能
6.1. Helm OCI 支持和 Red Hat Quay 复制链接链接已复制到粘贴板!
Red Hat Quay 等容器注册表最初设计为支持 Docker 镜像格式的容器镜像。为了促进 Docker 之外的额外运行时的使用,创建了开放容器项目(OCI)以提供围绕容器运行时和镜像格式的标准化。大多数容器注册表支持 OCI 标准化,因为它基于 Docker 镜像清单 V2,Schema 2 格式。
除了容器镜像外,还会出现各种工件,它不仅支持单个应用程序,而是支持整个 Kubernetes 平台。它们包括 Open Policy Agent (OPA)策略,用于安全和监管到 Helm chart 和 Operator,以便在应用程序部署中协助。
Red Hat Quay 是一个私有容器 registry,它不仅存储容器镜像,并支持整个工具生态系统来协助容器的管理。随着 Red Hat Quay 3.5 的发布,支持使用基于 OCI 的工件,特别是 Helm Charts,它已从技术预览(TP)升级,现在已具有正式发行(GA)状态。
当使用 OpenShift Operator 部署 Red Hat Quay 3.5 时,现在默认启用对 Helm 和 OCI 工件的支持。如果您需要 显式启用此功能,例如,如果之前已禁用该功能,或者您从未默认启用的版本升级了,请参阅明确启用 OCI 和 Helm 支持 部分。
6.1.1. Helm 和 OCI 的先决条件 复制链接链接已复制到粘贴板!
可信证书: Helm 客户端和 Quay 之间的通信通过 HTTPS 和 Helm 3.5 促进,支持只能通过 HTTPS 与可信证书通信的 registry。另外,操作系统必须信任 registry 公开的证书。以后的 Helm 发行版本的支持将允许不安全地与远程 registry 通信。请记住,请确保您的操作系统已配置为信任 Quay 使用的证书,例如:
$ sudo cp rootCA.pem /etc/pki/ca-trust/source/anchors/ $ sudo update-ca-trust extract-
实验性功能: 许多与 Helm 和 OCI registry 交互的命令使用
helm chart子命令。在编写本文时,Helm 中的 OCI 支持仍标记为"实验性"功能,必须明确启用。这可以通过设置环境变量HELM_EXPERIMENTAL_OCI=1来完成。 安装 Helm 客户端 : 从 https://github.com/helm/helm/releases 下载所需的版本,例如 https://get.helm.sh/helm-v3.5.3-linux-amd64.tar.gz。解包,并将 helm 二进制文件移到所需的目的地:
$ tar -zxvf helm-v3.5.3-linux-amd64.tar.gz $ mv linux-amd64/helm /usr/local/bin/helm-
在 Quay 中创建机构: 使用 Quay registry UI 创建用于存储 Helm chart 的新机构。例如,创建名为
helm的组织。
6.1.2. 在 Quay 中使用 Helm chart 复制链接链接已复制到粘贴板!
Helm 作为云原生计算基础基础(CNCF)的升级项目,成为 Kubernetes 的事实软件包管理器,因为它简化了如何打包和部署应用程序。Helm 使用名为 Charts 的打包格式,其中包含代表应用程序的 Kubernetes 资源。chart 可用于在仓库中常规发行版和消耗。Helm 仓库是一个 HTTP 服务器,它提供 index.yaml 元数据文件,以及可选的一组打包 chart。从 Helm 版本 3 开始,支持可在 OCI registry 中分发 chart 作为传统仓库的替代选择。为了演示如何将 Quay 用作 Helm chart 的 registry,Helm 仓库中的现有 chart 将用于展示与 chart 开发人员和用户的 OCI registry 的交互。
在以下示例中,从 Red Hat Community of Practice (CoP)存储库下载 etherpad chart 示例,并执行以下步骤推送到本地 Red Hat Quay 存储库:
- 添加适当的软件仓库
- 使用最新元数据更新存储库
-
下载并解压缩 chart 以创建名为
etherpad的本地目录
例如:
$ helm repo add redhat-cop https://redhat-cop.github.io/helm-charts
$ helm repo update
$ helm pull redhat-cop/etherpad --version=0.0.4 --untar
标记 chart 需要使用 helm chart save 命令 - 这对应于使用 podman tag 进行标记镜像。
$ helm chart save ./etherpad example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
ref: example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
digest: 6850d9b21dd4b87cf20ad49f2e2c7def9655c52ea573e1ddb9d1464eeb6a46a6
size: 3.5 KiB
name: etherpad
version: 0.0.4
0.0.4: saved
使用 helm chart list 命令查看 chart 的本地实例:
helm chart list
REF NAME VERSION DIGEST SIZE CREATED
example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4 etherpad 0.0.4 ce0233f 3.5 KiB 23 seconds
在推送 chart 前,使用 helm registry login 命令登录到存储库:
$ helm registry login example-registry-quay-quay-enterprise.apps.user1.example.com
Username: quayadmin
Password:
Login succeeded
使用 helm chart push 命令将 chart 推送到本地 Quay 存储库:
$ helm chart push example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
The push refers to repository [example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad]
ref: example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
digest: ce0233fd014992b8e27cc648cdabbebd4dd6850aca8fb8e50f7eef6f2f49833d
size: 3.5 KiB
name: etherpad
version: 0.0.4
0.0.4: pushed to remote (1 layer, 3.5 KiB total)
要测试推送是否正常工作,请删除本地副本,然后从存储库拉取 chart:
$ helm chart rm example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
$ rm -rf etherpad
$ helm chart pull example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
0.0.4: Pulling from example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad
ref: example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
digest: 6850d9b21dd4b87cf20ad49f2e2c7def9655c52ea573e1ddb9d1464eeb6a46a6
size: 3.5 KiB
name: etherpad
version: 0.0.4
Status: Downloaded newer chart for example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
使用 helm chart export 命令提取 chart 文件:
$ helm chart export example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
ref: example-registry-quay-quay-enterprise.apps.user1.example.com/helm/etherpad:0.0.4
digest: ce0233fd014992b8e27cc648cdabbebd4dd6850aca8fb8e50f7eef6f2f49833d
size: 3.5 KiB
name: etherpad
version: 0.0.4
Exported chart to etherpad/
6.1.3. OCI 和 Helm 配置 复制链接链接已复制到粘贴板!
现在,Red Hat Quay 3.5 中默认启用对 Helm 和 OCI 工件的支持。如果您需要显式启用此功能,例如,如果之前已禁用该功能,或者您从未默认启用的版本升级了,则需要在 Quay 配置中添加两个属性来启用使用 OCI 工件:
FEATURE_GENERAL_OCI_SUPPORT: true
FEATURE_HELM_OCI_SUPPORT: true
| 字段 | 类型 | 描述 |
|---|---|---|
| FEATURE_GENERAL_OCI_SUPPORT | 布尔值 |
启用 OCI 工件支持 |
| FEATURE_HELM_OCI_SUPPORT | 布尔值 |
启用对 Helm 工件的支持 |
6.1.4. 使用 Operator 配置 OCI 和 Helm 复制链接链接已复制到粘贴板!
可以在包含配置捆绑包的 secret 中提供对 Quay 配置的自定义。执行以下命令,它将在适当的命名空间中创建一个名为 quay-config-bundle 的新 secret,其中包含启用 OCI 支持的必要属性。
quay-config-bundle.yaml
apiVersion: v1
stringData:
config.yaml: |
FEATURE_GENERAL_OCI_SUPPORT: true
FEATURE_HELM_OCI_SUPPORT: true
kind: Secret
metadata:
name: quay-config-bundle
namespace: quay-enterprise
type: Opaque
在适当的命名空间中创建 secret,在本例中为 quay-enterprise :
$ oc create -n quay-enterprise -f quay-config-bundle.yaml
为 spec.configBundleSecret 字段指定 secret:
quay-registry.yaml
apiVersion: quay.redhat.com/v1
kind: QuayRegistry
metadata:
name: example-registry
namespace: quay-enterprise
spec:
configBundleSecret: quay-config-bundle
使用指定的配置创建 registry:
$ oc create -n quay-enterprise -f quay-registry.yaml