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.
Sobre o autor
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.
Mais como este
Navegue por canal
Automação
Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes
Inteligência artificial
Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente
Nuvem híbrida aberta
Veja como construímos um futuro mais flexível com a nuvem híbrida
Segurança
Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias
Edge computing
Saiba quais são as atualizações nas plataformas que simplificam as operações na borda
Infraestrutura
Saiba o que há de mais recente na plataforma Linux empresarial líder mundial
Aplicações
Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações
Programas originais
Veja as histórias divertidas de criadores e líderes em tecnologia empresarial
Produtos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Red Hat Cloud Services
- Veja todos os produtos
Ferramentas
- Treinamento e certificação
- Minha conta
- Suporte ao cliente
- Recursos para desenvolvedores
- Encontre um parceiro
- Red Hat Ecosystem Catalog
- Calculadora de valor Red Hat
- Documentação
Experimente, compre, venda
Comunicação
- Contate o setor de vendas
- Fale com o Atendimento ao Cliente
- Contate o setor de treinamento
- Redes sociais
Sobre a Red Hat
A Red Hat é a líder mundial em soluções empresariais open source como Linux, nuvem, containers e Kubernetes. Fornecemos soluções robustas que facilitam o trabalho em diversas plataformas e ambientes, do datacenter principal até a borda da rede.
Selecione um idioma
Red Hat legal and privacy links
- Sobre a Red Hat
- Oportunidades de emprego
- Eventos
- Escritórios
- Fale com a Red Hat
- Blog da Red Hat
- Diversidade, equidade e inclusão
- Cool Stuff Store
- Red Hat Summit