12.7. AWS でのカスタム RHCOS AMI のアップロード
カスタム Amazon Web Services (AWS) リージョンにデプロイする場合、そのリージョンに属するカスタム Red Hat Enterprise Linux CoreOS (RHCOS) Amazon Machine Image (AMI) をアップロードする必要があります。
前提条件
- AWS アカウントを設定している。
- 必要な IAM サービスロール で、Amazon S3 バケットを作成している。
- RHCOS VMDK ファイルを Amazon S3 にアップロードしている。RHCOS VMDK ファイルは、インストールする OpenShift Container Platform のバージョンと同じか、それ以下のバージョンである必要があります。
- AWS CLI をダウンロードし、これをコンピューターにインストールしている。Install the AWS CLI Using the Bundled Installer を参照してください。
手順
AWS プロファイルを環境変数としてエクスポートします。
$ export AWS_PROFILE=<aws_profile>1 - 1
beijingadminなどの AWS 認証情報を保持する AWS プロファイル名。
カスタム AMI に関連付けるリージョンを環境変数としてエクスポートします。
$ export AWS_DEFAULT_REGION=<aws_region>1 - 1
cn-north-1などの AWS リージョン
環境変数として Amazon S3 にアップロードした RHCOS のバージョンをエクスポートします。
$ export RHCOS_VERSION=<version>1 - 1
4.13.0などの RHCOS VMDK バージョン。
Amazon S3 バケット名を環境変数としてエクスポートします。
$ export VMIMPORT_BUCKET_NAME=<s3_bucket_name>containers.jsonファイルを作成し、RHCOS VMDK ファイルを定義します。$ cat <<EOF > containers.json { "Description": "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64", "Format": "vmdk", "UserBucket": { "S3Bucket": "${VMIMPORT_BUCKET_NAME}", "S3Key": "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64.vmdk" } } EOFRHCOS ディスクを Amazon EBS スナップショットとしてインポートします。
$ aws ec2 import-snapshot --region ${AWS_DEFAULT_REGION} \ --description "<description>" \1 --disk-container "file://<file_path>/containers.json"2 イメージインポートのステータスを確認します。
$ watch -n 5 aws ec2 describe-import-snapshot-tasks --region ${AWS_DEFAULT_REGION}出力例
{ "ImportSnapshotTasks": [ { "Description": "rhcos-4.7.0-x86_64-aws.x86_64", "ImportTaskId": "import-snap-fh6i8uil", "SnapshotTaskDetail": { "Description": "rhcos-4.7.0-x86_64-aws.x86_64", "DiskImageSize": 819056640.0, "Format": "VMDK", "SnapshotId": "snap-06331325870076318", "Status": "completed", "UserBucket": { "S3Bucket": "external-images", "S3Key": "rhcos-4.7.0-x86_64-aws.x86_64.vmdk" } } } ] }SnapshotIdをコピーして、イメージを登録します。RHCOS スナップショットからカスタム RHCOS AMI を作成します。
$ aws ec2 register-image \ --region ${AWS_DEFAULT_REGION} \ --architecture x86_64 \1 --description "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64" \2 --ena-support \ --name "rhcos-${RHCOS_VERSION}-x86_64-aws.x86_64" \3 --virtualization-type hvm \ --root-device-name '/dev/xvda' \ --block-device-mappings 'DeviceName=/dev/xvda,Ebs={DeleteOnTermination=true,SnapshotId=<snapshot_ID>}'4
これらの API の詳細は、AWS ドキュメントの Importing a Disk as a Snapshot Using VM Import/Export および Creating a Linux AMI from a snapshot を参照してください。