# 工作準備 ``` ## oc client wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux-amd64-rhel8.tar.gz ## oc mirror wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/oc-mirror.tar.gz tar zxf *.tar.gz chmod +x oc-mirror mv oc kubelet oc-mirror /usr/local/bin ##建立mirror專用的工作資料夾 mkdir mirror-workspace ``` ## 準備pull-secret Download your registry.redhat.io pull secret from Red Hat OpenShift Cluster Manager Convert your pull secret in JSON format: ``` $ cat ./pull-secret | jq . > <path>/<pull_secret_file_in_json> Copy the JSON file to the .docker directory: $ mkdir ~/.docker $ cp <path>/<pull_secret_file_in_json> ~/.docker/config.json ``` ## 準備ImageSetConfiguration cd mirror-workspace vi isc.yaml ``` kind: ImageSetConfiguration apiVersion: mirror.openshift.io/v2alpha1 mirror: operators: - catalog: registry.redhat.io/redhat/redhat-operator-index:v4.12 packages: - name: kubevirt-hyperconverged - name: mtv-operator - catalog: registry.redhat.io/redhat/redhat-operator-index:v4.16 packages: - name: kubevirt-hyperconverged - name: mtv-operator ``` --- # !!根據您的現況選擇對應的情境!! --- ## 情境1 : 直接從外部Internet透過工作機器mirror到內部 你的工作機器可以同時連外網跟內網 ``` cd mirror-workspace oc-mirror --v2 -c isc.yaml --loglevel debug --workspace file:///home/quickcluster/mirror-workspace docker://quay.io/rhn_support_jaliang/ocpv-mirror 2>&1 | tee oc-mirror-v2-logs-debug.txt 執行完成後會有以下資訊 2025/06/23 04:02:32 [INFO] : === Results === 2025/06/23 04:02:32 [INFO] : ✓ 348 / 348 operator images mirrored successfully 2025/06/23 04:02:32 [DEBUG] : concurrent channel worker time : 10m51.882654986s 2025/06/23 04:02:32 [INFO] : 📄 Generating IDMS file... 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/idms-oc-mirror.yaml does not exist, creating it 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources dir created 2025/06/23 04:02:32 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/idms-oc-mirror.yaml file created 2025/06/23 04:02:32 [INFO] : 📄 No images by tag were mirrored. Skipping ITMS generation. 2025/06/23 04:02:32 [INFO] : 📄 Generating CatalogSource file... 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cs-redhat-operator-index-v4-12.yaml does not exist, creating it 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources dir created 2025/06/23 04:02:32 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cs-redhat-operator-index-v4-12.yaml file created 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cs-redhat-operator-index-v4-16.yaml does not exist, creating it 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources dir created 2025/06/23 04:02:32 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cs-redhat-operator-index-v4-16.yaml file created 2025/06/23 04:02:32 [INFO] : 📄 Generating ClusterCatalog file... 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cc-redhat-operator-index-v4-12.yaml does not exist, creating it 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources dir created 2025/06/23 04:02:32 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cc-redhat-operator-index-v4-12.yaml file created 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cc-redhat-operator-index-v4-16.yaml does not exist, creating it 2025/06/23 04:02:32 [DEBUG] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources dir created 2025/06/23 04:02:32 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cc-redhat-operator-index-v4-16.yaml file created 2025/06/23 04:02:32 [INFO] : mirror time : 10m56.585611007s 2025/06/23 04:02:32 [INFO] : 👋 Goodbye, thank you for using oc-mirror ``` Mirror完成後會於working-dir/cluster-resources產生 ImageDigestMirrorSet, ImageTagMirrorSet and CatalogSource resources. 使用oc apply套用這些產生出來的yaml檔案,後續即可在OCP上安裝該Operator ## 情境2 : 先將外部Image另存成檔案,再搬遷到內部Registry 預備500G容量的硬碟空間 ``` cd mirror-workspace # 用oc mirror將operator的image複製到本地 oc mirror -c isc.yaml file:///home/quickcluster/mirror-workspace --v2 #執行完成後會有以下資訊 2025/06/23 04:57:50 [INFO] : === Results === 2025/06/23 04:57:50 [INFO] : ✓ 99 / 99 operator images mirrored successfully 2025/06/23 04:57:50 [INFO] : 📦 Preparing the tarball archive... 2025/06/23 04:59:50 [INFO] : mirror time : 14m45.343273846s 2025/06/23 04:59:50 [INFO] : 👋 Goodbye, thank you for using oc-mirror ``` 執行完成後複製整個mirror-workspace資料夾到可以存取內部registry的機器 ``` #使用oc mirror將mirror-workspace內的檔案複製到registry oc mirror -c isc.yaml --from file://mirror-workspace docker://quay.io/rhn_support_jaliang/ --v2 2025/06/23 05:10:14 [INFO] : === Results === 2025/06/23 05:10:14 [INFO] : ✓ 99 / 99 operator images mirrored successfully 2025/06/23 05:10:14 [INFO] : 📄 Generating IDMS file... 2025/06/23 05:10:14 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/idms-oc-mirror.yaml file created 2025/06/23 05:10:14 [INFO] : 📄 No images by tag were mirrored. Skipping ITMS generation. 2025/06/23 05:10:14 [INFO] : 📄 Generating CatalogSource file... 2025/06/23 05:10:14 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cs-redhat-operator-index-v4-12.yaml file created 2025/06/23 05:10:14 [INFO] : 📄 Generating ClusterCatalog file... 2025/06/23 05:10:14 [INFO] : /home/quickcluster/mirror-workspace/working-dir/cluster-resources/cc-redhat-operator-index-v4-12.yaml file created 2025/06/23 05:10:14 [INFO] : mirror time : 2m39.268284342s 2025/06/23 05:10:14 [INFO] : 👋 Goodbye, thank you for using oc-mirror ``` upload完成後會於working-dir/cluster-resources產生 ImageDigestMirrorSet, ImageTagMirrorSet and CatalogSource resources. 用oc apply套用這些產生出來的yaml檔案,後續即可在OCP上安裝該Operator