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 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.