In this post:
-
Get a brief explanation of Image Builder
-
Walk through an example of how to prepare an Azure account for an image upload, build a customized RHEL image, ship it to Azure, and start a VM.
Clouds deliver a flexible, dynamic platform for workloads of all sizes with incredible amounts of customization. Most clouds have an image marketplace where customers select different OS images for their workloads, but Red Hat Enterprise Linux (RHEL) offers a unique opportunity to build your own image with Image Builder.
Microsoft Azure is one of Red Hat’s certified cloud providers and they offer a wide array of cloud services in many countries throughout the world. Although you can use a pre-built RHEL image on Azure today, you also have the opportunity to build a customized image with Image Builder and ship it to Azure directly.
Image Builder empowers IT professionals with a simple image build process. Users provide image configuration via a simple TOML file on the command line or via the Cockpit web interface. Image Builder then builds the image in various formats, including raw, qcow2, and several others. In addition, it uploads the image into the cloud of your choice so you can start deploying in a flash!
This post explains how to prepare your Microsoft Azure account for an image build, how to build an image with Image Builder on RHEL 8, and how to launch that image in Azure.
Get your Azure account ready
Start by visiting the Azure Portal and authenticating your account. Azure provides resource groups as a way to keep resources organized. To create a resource group:
-
Type resource groups into the search bar at the top and click on Resource groups in the list.
-
Click Create and provide a name for the resource group on the next page.
-
Click Review + Create and then Create.
Image Builder needs to upload a storage blob to a storage container, so we need a storage account and container first:
-
Type storage account into the search bar and click Storage accounts in the list.
-
Click Create and make sure your Resource group appears in the dropdown list.
-
Enter a name for your storage account in Storage Account Name.
-
Click Review + Create and Create.
-
Wait a few moments for the deployment to finish and then click Go to resource.
-
On the left side, click Containers and then click + Container at the top to add a container.
-
Choose a name for the container on the far right, then click Create.
We now have a storage account and container that Image Builder can use to store our image. The last step is to get your storage access key since Image Builder uses it for authentication when it uploads:
-
Click Access Keys on the left side.
-
Click Show Keys at the top.
-
In the key1 section, look for the box under Key and copy the contents (you will need this later).
Your Azure account is ready to go!
Getting started with Image Builder
Image Builder includes a few different components:
-
osbuild: completes all of the low level image build tasks.
-
osbuild-composer: offers a simple API for building and managing images.
-
composer-cli: provides a command line interface for building and managing images.
Start by installing some packages on RHEL 8.4 or later:
$ sudo dnf install osbuild-composer composer-cli
The osbuild-composer service starts via socket activation only when you need it. Start the socket:
Users must be in the weldr group to build images. Add your username to the weldr group:
$ sudo usermod -a -G weldr YOUR_USERNAME
Log out of your RHEL 8 system and log back in. You should now be able to talk to the osbuild-composer API:
$ composer-cli status show
API server status:
Database version: 0
Database supported: True
Schema version: 0
API version: 1
Backend: osbuild-composer
Build: devel
provider = "azure" [settings] storageAccount = "your storage account name" storageAccessKey = "storage access key you copied in the Azure portal" container = "your storage container name"
Now, we tell Image Builder how to build our image. As a fun experiment, let’s build a RHEL image that contains Image Builder so that you can build more images in an Azure VM! Image Builder calls these “blueprints.” Save this blueprint file as imagebuilder.toml:
name = "imagebuilder" description = "An image with Image Builder already installed" version = "0.0.1" [[packages]] name = "osbuild-composer" [[packages]] name = "composer-cli" [customizations] hostname = "imagebuilder.local" [customizations.services] enabled = ["osbuild-composer.socket"]
We can push our blueprint into the API and solve the package dependencies:
$ composer-cli blueprints push imagebuilder.toml $ composer-cli blueprints depsolve imagebuilder
Let’s build and ship our image! The following command builds a 10GB image called image-builder-azure using our imagebuilder blueprint and uploading to Azure with the configuration in our azure.toml file:
$ composer-cli compose start --size 10240 imagebuilder vhd image-builder-azure azure.toml Compose c1fde40f-2f10-4a52-92d3-c00b62c32f17 added to the queue $ composer-cli compose status c1fde40f-2f10-4a52-92d3-c00b62c32f17 RUNNING Fri Nov 5 09:46:38 2021 imagebuilder 0.0.1 vhd
On most systems, the image build takes about 5-10 minutes, but the upload portion depends heavily on your internet connection speeds for uploading files. You can follow along with the progress by watching the system journal:
$ sudo journalctl -af -u osbuild-worker@1.service osbuild-worker[26576]: Running 'osbuild' job c1fde40f-2f10-4a52-92d3-c00b62c32f17 --- SNIP --- osbuild-worker[26576]: 2021/11/05 09:56:14 Job c1fde40f-2f10-4a52-92d3-c00b62c32f17 finished osbuild-worker[26576]: Waiting for a new job...
Launching a VM in Azure
The fun part has arrived! Let’s go back to the Azure portal to verify that our image uploaded properly:
-
Type storage account into the search bar and click Storage accounts in the list.
-
Find the storage account you created earlier and click it.
-
Click Containers on the left and click your container on the right side.
-
You should see a vhd file in the list (mine is image-builder-azure.vhd from the command line).
-
Check the size and ensure it matches the size you specified on the command line.
Our next step involves creating the virtual machine image so we can launch a VM:
-
Type images into the search bar at the top and click Images from the list.
-
Click + Create.
-
Choose the resource group you used earlier from the dropdown list.
-
Enter a name for the image.
-
Select Linux for the OS type.
-
Select Gen 2 for the VM generation.
-
Under Storage Blob, click Browse and click through the storage account and container until you reach your VHD file.
-
Click Select at the bottom of the screen.
-
Choose an Account Type (Standard SSD works fine for this example).
-
Click Review + Create and then Create.
-
Wait a few moments for the image creation and then click Go to resource.
Let’s launch the VM:
-
Click + Create VM at the top.
-
Choose a name for your virtual machine.
-
Complete the Size and Administrator account sections.
-
Click Review + Create and then Create.
Your VM is on the way! The next screen shows your deployment progress. Once it finishes, click on the virtual machine name to retrieve the public IP address of the instance to connect via ssh:
$ ssh username@IP_ADDRESS [username@imagebuilder ~]$ cat /etc/redhat-release Red Hat Enterprise Linux release 8.4 (Ootpa) [username@imagebuilder ~]$ sudo composer-cli status show API server status: Database version: 0 Database supported: True Schema version: 0 API version: 1 Backend: osbuild-composer Build: devel
Wrapping up
In this example, we prepared an Azure account for an image upload, built a customized RHEL image, shipped it to Azure, and started a VM. This is only a fraction of what you can build with Image Builder. It can also pull RPMs from your own custom repositories and allow you to stack your code and configuration on top of a stable RHEL base. This makes Image Builder a great part of any continuous integration/continuous delivery (CI/CD) pipeline.
Take a look at the Image Builder documentation for RHEL 8 to learn more about customizations and capabilities. You can also learn more about the upstream project, OSBuild, and join the upstream community.
執筆者紹介
Major Hayden is a Principal Software Engineer at Red Hat with a focus on making it easier to deploy Red Hat Enterprise Linux wherever a customer needs it. He is also an amateur radio operator (W5WUT), and he maintains a technical blog at major.io.
チャンネル別に見る
自動化
テクノロジー、チームおよび環境に関する IT 自動化の最新情報
AI (人工知能)
お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート
オープン・ハイブリッドクラウド
ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。
セキュリティ
環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報
エッジコンピューティング
エッジでの運用を単純化するプラットフォームのアップデート
インフラストラクチャ
世界有数のエンタープライズ向け Linux プラットフォームの最新情報
アプリケーション
アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細
オリジナル番組
エンタープライズ向けテクノロジーのメーカーやリーダーによるストーリー
製品
ツール
試用、購入、販売
コミュニケーション
Red Hat について
エンタープライズ・オープンソース・ソリューションのプロバイダーとして世界をリードする Red Hat は、Linux、クラウド、コンテナ、Kubernetes などのテクノロジーを提供しています。Red Hat は強化されたソリューションを提供し、コアデータセンターからネットワークエッジまで、企業が複数のプラットフォームおよび環境間で容易に運用できるようにしています。
言語を選択してください
Red Hat legal and privacy links
- Red Hat について
- 採用情報
- イベント
- 各国のオフィス
- Red Hat へのお問い合わせ
- Red Hat ブログ
- ダイバーシティ、エクイティ、およびインクルージョン
- Cool Stuff Store
- Red Hat Summit