第 4 章 使用 Quay Operator 部署 Quay
Operator 可从命令行或 OpenShift 控制台部署,但基本步骤相同。
4.1. 从命令行部署 Red Hat Quay 复制链接链接已复制到粘贴板!
-
创建一个命名空间,如
quay-enterprise
。 - 如果要预先配置部署的各个方面,为 config 捆绑包创建 secret
在名为
quayregistry.yaml
的文件中创建QuayRegistry
自定义资源对于最小部署,使用所有默认值:
quayregistry.yaml:
apiVersion: quay.redhat.com/v1 kind: QuayRegistry metadata: name: example-registry namespace: quay-enterprise
apiVersion: quay.redhat.com/v1 kind: QuayRegistry metadata: name: example-registry namespace: quay-enterprise
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果要具有一些组件非受管,请在
spec
字段中添加此信息。例如,最小部署可能类似如下:quayregistry.yaml:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您已创建了配置捆绑包,如
init-config-bundle-secret
,在quayregistry.yaml
文件中引用它:quayregistry.yaml:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
在指定的命名空间中创建
QuayRegistry
:oc create -f quayregistry.yaml
$ oc create -f quayregistry.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 如需有关如何跟踪部署进度的信息,请参阅 监控和调试部署过程。
等待
status.registryEndpoint
填充。oc get quayregistry -n quay-enterprise example-registry -o jsonpath="{.status.registryEndpoint}" -w
$ oc get quayregistry -n quay-enterprise example-registry -o jsonpath="{.status.registryEndpoint}" -w
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.1.1. 使用命令行查看创建的组件 复制链接链接已复制到粘贴板!
使用 oc get pods
命令查看部署的组件:
4.1.2. Pod 横向自动扩展(HPA) 复制链接链接已复制到粘贴板!
默认部署显示了以下正在运行的 pod:
-
Quay 应用本身的两个 pod(
example-registry-quay-app-*'
) -
用于 Quay 日志记录的 Redis pod(
example-registry-quay-redis-*
) -
Quay 用于元数据存储的 PostgreSQL 的一个数据库 pod(
example-registry-quay-database-*
) -
用于 Quay 配置编辑器的一个 pod(
example-registry-quay-config-editor-*
) -
两个 Quay 镜像 pod(
example-registry-quay-mirror-*
) -
Clair 应用的两个 pod(
example-registry-clair-app-*
) -
Clair 的 PostgreSQL pod(
example-registry-clair-postgres-*
)
因为 HPA 默认配置为 受管
,Quay 的 pod 数量将 Clair 和存储库镜像设置为 2。这有助于在通过 Operator 更新/配置 Quay 或重新调度事件期间出现停机的问题。
oc get hpa -n quay-enterprise
$ oc get hpa -n quay-enterprise
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
example-registry-clair-app Deployment/example-registry-clair-app 16%/90%, 0%/90% 2 10 2 13d
example-registry-quay-app Deployment/example-registry-quay-app 31%/90%, 1%/90% 2 20 2 13d
example-registry-quay-mirror Deployment/example-registry-quay-mirror 27%/90%, 0%/90% 2 20 2 13d
4.1.3. 使用 API 创建第一个用户 复制链接链接已复制到粘贴板!
当使用 API 创建第一个用户时,必须满足以下条件:
-
配置选项
FEATURE_USER_INITIALIZE
必须设置为true
- 数据库中没有用户
如需有关预配置部署的更多信息,请参阅 预配置 Quay 以实现自动化
4.1.3.1. 调用 API 复制链接链接已复制到粘贴板!
使用 status.registryEndpoint
URL,调用 /api/v1/user/initialize
API,传递用户名、密码和电子邮件地址。您还可以通过指定 "access_token": true
来请求 OAuth 令牌。
curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayadmin", "password":"quaypass123", "email": "quayadmin@example.com", "access_token": true}'
$ curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayadmin", "password":"quaypass123", "email": "quayadmin@example.com", "access_token": true}'
{"access_token":"6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED", "email":"quayadmin@example.com","encrypted_password":"1nZMLH57RIE5UGdL/yYpDOHLqiNCgimb6W9kfF8MjZ1xrfDpRyRs9NUnUuNuAitW","username":"quayadmin"}
{"access_token":"6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED", "email":"quayadmin@example.com","encrypted_password":"1nZMLH57RIE5UGdL/yYpDOHLqiNCgimb6W9kfF8MjZ1xrfDpRyRs9NUnUuNuAitW","username":"quayadmin"}
如果成功,该方法返回一个带有用户名、电子邮件和加密密码的对象。如果用户已存在于数据库中,则返回错误:
curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayuser2", "password":"quaypass123", "email": "quayuser2@example.com"}'
$ curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayuser2", "password":"quaypass123", "email": "quayuser2@example.com"}'
{"message":"Cannot initialize user in a non-empty database"}
{"message":"Cannot initialize user in a non-empty database"}
密码必须至少为 8 个字符,且不包含空格:
curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayadmin", "password":"pass123", "email": "quayadmin@example.com"}'
$ curl -X POST -k https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/user/initialize --header 'Content-Type: application/json' --data '{ "username": "quayadmin", "password":"pass123", "email": "quayadmin@example.com"}'
{"message":"Failed to initialize user: Invalid password, password must be at least 8 characters and contain no whitespace."}
{"message":"Failed to initialize user: Invalid password, password must be at least 8 characters and contain no whitespace."}
4.1.3.2. 使用 OAuth 令牌 复制链接链接已复制到粘贴板!
现在,您可以在指定返回的 OAuth 代码调用 Quay API 的剩余部分。例如,获取当前用户的列表:
curl -X GET -k -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/superuser/users/
$ curl -X GET -k -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/superuser/users/
在本例中,quayadmin
用户的详细信息返回,因为它是目前创建的唯一用户。
4.1.3.2.1. 创建机构 复制链接链接已复制到粘贴板!
要创建机构,使用 POST 调用 api/v1/organization/
端点:
curl -X POST -k --header 'Content-Type: application/json' -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/organization/ --data '{"name": "testorg", "email": "testorg@example.com"}'
$ curl -X POST -k --header 'Content-Type: application/json' -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://example-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/organization/ --data '{"name": "testorg", "email": "testorg@example.com"}'
"Created"
"Created"
4.1.3.2.2. 获取机构详情 复制链接链接已复制到粘贴板!
检索您创建的机构详情:
curl -X GET -k --header 'Content-Type: application/json' -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://min-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/organization/testorg
$ curl -X GET -k --header 'Content-Type: application/json' -H "Authorization: Bearer 6B4QTRSTSD1HMIG915VPX7BMEZBVB9GPNY2FC2ED" https://min-registry-quay-quay-enterprise.apps.docs.quayteam.org/api/v1/organization/testorg
4.1.4. 监控和调试部署过程 复制链接链接已复制到粘贴板!
Red Hat Quay 3.6 提供了新的功能,可在部署阶段排除问题。QuayRegistry 对象中的状态可帮助您在部署过程中监控组件的健康状态,以帮助您调试可能出现的问题:
oc get quayregistry -n quay-enterprise -o yaml
$ oc get quayregistry -n quay-enterprise -o yaml
部署后,QuayRegistry 对象会显示基本配置:
使用 oc get pods
命令查看部署组件的当前状态:
在部署进行过程中,QuayRegistry 对象会显示当前状态。在本实例中,数据库迁移就位,其他组件也等到此完成后才会等待。
当部署过程成功完成时,QuayRegistry 对象中的状态不会显示不健康的组件: