11.5. 使用 Quay Bridge Operator
使用以下步骤使用 Quay Bridge Operator。
先决条件
- 已安装 Red Hat Quay Operator。
- 已作为集群管理员登录到 OpenShift Container Platform。
- 已登陆到 Red Hat Quay registry。
- 已安装 Quay Bridge Operator。
-
您已配置了
QuayIntegration自定义资源。
流程
输入以下命令创建一个名为
e2e-demo的新 OpenShift Container Platform 项目:$ oc new-project e2e-demo在创建了新项目后,Red Hat Quay 中会创建一个新机构。导航到 Red Hat Quay registry,并确认您已创建一个名为
openshift_e2e-demo的新组织。注意如果
QuayIntegration资源中的 clusterID 使用不同的值,则机构的openshift值可能会有所不同。- 在 Red Hat Quay UI 上,单击新组织的名称,如 openshift_e2e-demo。
在导航窗格中,单击 Robot Accounts。作为新项目的一部分,应创建以下 Robot Accounts:
- openshift_e2e-demo+deployer
- openshift_e2e-demo+default
- openshift_e2e-demo+builder
输入以下命令确认已创建了三个包含与适用 Robot Accounts 关联的 Docker 配置的 secret:
$ oc get secrets builder-quay-openshift deployer-quay-openshift default-quay-openshift输出示例
stevsmit@stevsmit ocp-quay $ oc get secrets builder-quay-openshift deployer-quay-openshift default-quay-openshift NAME TYPE DATA AGE builder-quay-openshift kubernetes.io/dockerconfigjson 1 77m deployer-quay-openshift kubernetes.io/dockerconfigjson 1 77m default-quay-openshift kubernetes.io/dockerconfigjson 1 77m输入以下命令显示
builderServiceAccount (SA)的详细信息,包括其 secret、令牌过期以及关联的角色和角色绑定。这样可确保项目通过 Quay Bridge Operator 集成。$ oc describe sa builder default deployer输出示例
... Name: builder Namespace: e2e-demo Labels: <none> Annotations: <none> Image pull secrets: builder-dockercfg-12345 builder-quay-openshift Mountable secrets: builder-dockercfg-12345 builder-quay-openshift Tokens: builder-token-12345 Events: <none> ...输入以下命令来创建并部署名为
httpd-template的新应用程序:$ oc new-app --template=httpd-example输出示例
--> Deploying template "e2e-demo/httpd-example" to project e2e-demo ... --> Creating resources ... service "httpd-example" created route.route.openshift.io "httpd-example" created imagestream.image.openshift.io "httpd-example" created buildconfig.build.openshift.io "httpd-example" created deploymentconfig.apps.openshift.io "httpd-example" created --> Success Access your application via route 'httpd-example-e2e-demo.apps.quay-ocp.gcp.quaydev.org' Build scheduled, use 'oc logs -f buildconfig/httpd-example' to track its progress. Run 'oc status' to view your app.运行此命令后,会创建
BuildConfig、ImageStream、Service、Route和DeploymentConfig资源。创建ImageStream资源时,会在 Red Hat Quay 中创建关联的存储库。例如:
当 Apache HTTPD 镜像位于
openshift命名空间中的 Apache HTTPD 镜像被解决时,BuildConfig的ImageChangeTrigger会触发新的 Build。创建新 Build 时,MutatingWebhookConfiguration会自动重写输出以指向 Red Hat Quay。您可以通过运行以下命令来查询构建的输出字段来确认构建已完成:$ oc get build httpd-example-1 --template='{{ .spec.output.to.name }}'输出示例
example-registry-quay-quay-enterprise.apps.quay-ocp.gcp.quaydev.org/openshift_e2e-demo/httpd-example:latest-
在 Red Hat Quay UI 上,导航到
openshift_e2e-demo组织,再选择 httpd-example 存储库。 -
单击导航窗格中的 Tags,并确认
latest标签已成功推送。 输入以下命令来确保 latest 标签已解决:
$ oc describe is httpd-example输出示例
Name: httpd-example Namespace: e2e-demo Created: 55 minutes ago Labels: app=httpd-example template=httpd-example Description: Keeps track of changes in the application image Annotations: openshift.io/generated-by=OpenShiftNewApp openshift.io/image.dockerRepositoryCheck=2023-10-02T17:56:45Z Image Repository: image-registry.openshift-image-registry.svc:5000/e2e-demo/httpd-example Image Lookup: local=false Unique Images: 0 Tags: 1 latest tagged from example-registry-quay-quay-enterprise.apps.quay-ocp.gcp.quaydev.org/openshift_e2e-demo/httpd-example:latestImageStream被解决后,应触发新部署。输入以下命令生成 URL 输出:$ oc get route httpd-example --template='{{ .spec.host }}'输出示例
httpd-example-e2e-demo.apps.quay-ocp.gcp.quaydev.org- 访问此 URL。如果显示示例网页,则代表部署成功。
输入以下命令删除资源并清理 Red Hat Quay 存储库:
$ oc delete project e2e-demo注意命令将等待到项目资源已被删除。这可以通过将
--wait=false添加到上述命令来绕过-
命令完成后,导航到您的 Red Hat Quay 存储库,并确认
openshift_e2e-demo组织不再可用。
其他资源
- 最佳实践规定客户端和镜像 registry 之间的所有通信都通过安全的方法促进。通信应该与各方之间的证书信任利用 HTTPS/TLS。虽然 Red Hat Quay 可以配置为提供不安全的配置,但应该在服务器上使用正确的证书并在客户端上配置。按照 OpenShift Container Platform 文档 在容器运行时级别添加和删除证书。