4.5. 准备您的镜像主机
在使用 oc-mirror 插件镜像(mirror)前,您必须安装插件并创建容器镜像 registry 凭据文件,以允许从红帽镜像到您的镜像。
4.5.1. 安装 oc-mirror OpenShift CLI 插件
要使用 oc-mirror OpenShift CLI 插件来镜像 registry 镜像,您必须安装插件。如果您在一个完全断开连接的环境中镜像镜像集,请确保在具有互联网访问的主机上的 oc-mirror 插件以及可访问镜像 registry 的断开连接的环境中安装 oc-mirror 插件。
先决条件
-
已安装 OpenShift CLI(
oc
)。
流程
下载 oc-mirror CLI 插件。
- 进入到 OpenShift Cluster Manager Hybrid Cloud Console 的 Downloads 页面。
- 在 OpenShift disconnected 安装工具部分下,点 Download for OpenShift Client(oc)mirror 插件 并保存该文件。
解压归档:
$ tar xvzf oc-mirror.tar.gz
如有必要,将插件文件更新为可执行。
$ chmod +x oc-mirror
注意不要重命名
oc-mirror
文件。通过将文件放在
PATH
中,例如/usr/local/bin
,安装 oc-mirror CLI 插件:$ sudo mv oc-mirror /usr/local/bin/.
验证
运行
oc mirror help
来验证插件是否已成功安装:$ oc mirror help
其他资源
4.5.2. 配置允许对容器镜像进行镜像的凭证
创建容器镜像 registry 凭证文件,允许将红帽的镜像镜像到您的镜像环境中。
安装集群时不要使用此镜像 registry 凭据文件作为 pull secret。如果在安装集群时提供此文件,集群中的所有机器都将具有镜像 registry 的写入权限。
此过程需要您可以对镜像 registry 上的容器镜像 registry 进行写操作,并将凭证添加到 registry pull secret。
先决条件
- 您已将镜像 registry 配置为在断开连接的环境中使用。
- 您在镜像 registry 中标识了镜像仓库的位置,以将容器镜像镜像(mirror)到这个位置。
- 您置备了一个镜像 registry 帐户,允许将镜像上传到该镜像仓库。
流程
在安装主机上完成以下步骤:
-
下载您的
registry.redhat.io
pull secret(从Red Hat OpenShift Cluster Manager)。 以 JSON 格式创建您的 pull secret 副本:
$ cat ./pull-secret | jq . > <path>/<pull_secret_file_in_json> 1
- 1
- 指定到存储 pull secret 的文件夹的路径,以及您创建的 JSON 文件的名称。
该文件类似于以下示例:
{ "auths": { "cloud.openshift.com": { "auth": "b3BlbnNo...", "email": "you@example.com" }, "quay.io": { "auth": "b3BlbnNo...", "email": "you@example.com" }, "registry.connect.redhat.com": { "auth": "NTE3Njg5Nj...", "email": "you@example.com" }, "registry.redhat.io": { "auth": "NTE3Njg5Nj...", "email": "you@example.com" } } }
将文件保存为
~/.docker/config.json
或$XDG_RUNTIME_DIR/containers/auth.json
:如果
.docker
或$XDG_RUNTIME_DIR/containers
目录不存在,请输入以下命令来创建:$ mkdir -p <directory_name>
其中
<directory_name>
是~/.docker
或$XDG_RUNTIME_DIR/containers
。输入以下命令将 pull secret 复制到适当的目录中:
$ cp <path>/<pull_secret_file_in_json> <directory_name>/<auth_file>
其中
<directory_name>
是~/.docker
或$XDG_RUNTIME_DIR/containers
,<auth_file>
是config.json
或auth.json
。
为您的镜像 registry 生成 base64 编码的用户名和密码或令牌:
$ echo -n '<user_name>:<password>' | base64 -w0 1 BGVtbYk3ZHAtqXs=
- 1
- 通过
<user_name>
和<password>
指定 registry 的用户名和密码。
编辑 JSON 文件并添加描述 registry 的部分:
"auths": { "<mirror_registry>": { 1 "auth": "<credentials>", 2 "email": "you@example.com" } },
该文件类似于以下示例:
{ "auths": { "registry.example.com": { "auth": "BGVtbYk3ZHAtqXs=", "email": "you@example.com" }, "cloud.openshift.com": { "auth": "b3BlbnNo...", "email": "you@example.com" }, "quay.io": { "auth": "b3BlbnNo...", "email": "you@example.com" }, "registry.connect.redhat.com": { "auth": "NTE3Njg5Nj...", "email": "you@example.com" }, "registry.redhat.io": { "auth": "NTE3Njg5Nj...", "email": "you@example.com" } } }