Kubernetesクラスターでは、イメージの移行と同期が必要です。 image-syncerを使用して、複数のイメージを自己管理イメージリポジトリからAlibaba Cloud Container Registry (ACR) に同時に移行および同期できます。 本ページでは、image-syncer を使用してコンテナイメージを移行する方法について説明します。
背景情報
イメージの数が少ない場合は、docker pullコマンドとdocker pushコマンドを実行して、イメージをKubernetesワークロードからContainer Service for Kubernetes (ACK) に移行できます。 コマンドを実行して、100を超えるイメージ、またはTBレベルのデータを格納するイメージリポジトリを移行すると、移行プロセスが完了するまでに長い時間がかかり、データが失われる可能性があります。 他のクラウドプロバイダーによって作成および保守されているKubernetesクラスターと比較して、ACKはサービスコスト、保守費用、使いやすさ、および長期的な安定性の点で優れています。 KubernetesワークロードをACKに移行するクラウドプロバイダーが増えています。 大規模なイメージ移行の問題を解決するために、Alibaba Cloudによって開発されたオープンソースのツールimage-syncerは、クラウドサービスプロバイダーがイメージを移行するのに役立つイメージ同期レプリケーション機能を提供します。 イメージリポジトリの最大容量は3テラバイトを超えています。 image-syncerを実行するサーバーは、サーバーの帯域幅を最大限に活用することができ、サーバーのディスク容量に対する要件はありません。
イメージ同期の概要
アプリケーションを自己管理KubernetesクラスターからACKクラスターに移行するには、イメージリポジトリ間のイメージ移行と同期が必要です。 従来のイメージ同期方法では、docker pullまたはdocker pushコマンドを含むスクリプトを使用し、次の制限があります。
この方法は、ディスクストレージに依存し、完了するまでに長い時間を要し、大規模なイメージ移行を困難にする。
Dockerデーモンが必要です。これにより、同時にプルまたはプッシュできるイメージの数が制限されます。
一部の機能を実装するには、HTTP API操作が必要です。 そのため、複雑な同期スクリプトを作成する必要があります。
image-syncerは、多数の画像を同時に移行または同期するための使いやすいツールです。 image-syncerを使用して、ACR、Docker Hub、Quay.io、Harborなど、Docker Registry V2に基づくほぼすべてのイメージリポジトリサービスとの間でDockerイメージを同期できます。 このツールは、本番環境でTBレベルのイメージを移行するために使用されます。 詳細については、『image-syncer』をご参照ください。
特徴
image-syncer には次の機能があります。
複数のソースイメージリポジトリのイメージを、Docker Hub、Quay.io、Alibaba Cloud Container Registry、Harborなどの複数の宛先イメージリポジトリに同期させます。
Docker Registry V2 に基づく Docker イメージリポジトリサービスをサポートします。
メモリとネットワークリソースのみを使用してイメージを同期します。 イメージは、宛先イメージリポジトリが存在するサーバーのディスクには保存されません。 これにより、同期効率が向上する。
増分同期をサポートします。同期イメージは再同期されません。
同時同期をサポートします。 設定ファイルで同時にプルまたはプッシュできるイメージの数を変更できます。
失敗した同期タスクを自動的に再試行して、ネットワークのジッターによって引き起こされるほとんどのイメージ同期の問題を解決します。
Dockerデーモンなどのプログラムは不要です。 同期が必要なレジストリネットワークにランタイム環境が接続されていることを確認する必要があります。
image-syncerツールを使用して、イメージリポジトリからのイメージの移行、コピー、増分同期を実行できます。 image-syncerのハードウェアリソース要件は低いです。 image-syncerは、同期終了時に同期に失敗したイメージの数をカウントし、問題の特定に役立つ詳細なログを提供します。
準備
image-syncerを使用するには、設定ファイルを用意します。 次のコードブロックは、構成ファイルの例を示しています。
{
"auth": { // This field specifies the authentication information. Each object consists of a username and a password that are required to access a registry. In most cases, image-syncer must have permissions to pull images from and access tags in the source repository.
// image-syncer must have permissions to push images to and create repositories in the destination registry. If no authentication information is provided for a registry, image-syncer accesses the registry in anonymous mode.
"quay.io": { // The URL of the registry, which must be the same as the URL of the registry in image URLs.
"username": "xxx", // Optional. The username.
"password": "xxxxxxxxx", // Optional. The password.
"insecure": true // Optional. Specifies whether the repository is accessed by using HTTP. Default value: false. Only image-syncer of V1.0.1 and later support this parameter.
},
"registry.cn-beijing.aliyuncs.com": {
"username": "xxx",
"password": "xxxxxxxxx"
},
"registry.hub.docker.com": {
"username": "xxx",
"password": "xxxxxxxxxx"
}
},
"images": {
// The field that describes image synchronization rules. Each rule is a key-value pair. The key specifies the URL of the source repository and the value specifies the URL of the destination repository.
// You cannot synchronize an entire namespace or registry based on one rule. You can synchronize only one repository based on one rule.
// The URLs of the source and destination repositories are in the format of registry/namespace/repository:tag, which is similar to the image URL format used in the docker pull or docker push command.
// The URL of the source repository must contain registry/namespace/repository. If the URL of the destination repository is not an empty string, it must also contain registry/namespace/repository.
// The URL of the source repository cannot be an empty string. To synchronize images from a source repository to multiple destination repositories, you must configure multiple rules.
// The name and tags of the destination repository can be different from those of the source repository. In this case, the image synchronization rule works in the same way as the combination of the docker pull, docker tag, and docker push commands.
"quay.io/coreos/kube-rbac-proxy": "quay.io/ruohe/kube-rbac-proxy",
"xxxx":"xxxxx",
"xxx/xxx/xx:tag1,tag2,tag3":"xxx/xxx/xx"
// If the URL of the source repository does not contain tags, all images in the source repository are synchronized to the destination repository with the original tags. In this case, the URL of the destination repository cannot contain tags.
// If the URL of source repository contains only one tag, only images that has this tag in the source repository are synchronized to the destination repository. If the URL of the destination repository does not contain a tag, synchronized images keep the original tag.
// If the URL of the source repository contains multiple tags that are separated with commas (,), such as "a/b/c:1,2,3", the URL of the destination repository cannot contain tags. Synchronized images keep the original tags.
// If the URL of the destination repository is an empty string, images are synchronized to a repository that has the same name and tags in the default namespace of the default registry. The default registry and namespace can be set through command parameters or environment variables.
}
}例:
セルフマネージドHarborプロジェクトからContainer Registry Enterprise Editionへのイメージの同期