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.
À propos de l'auteur
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.
Contenu similaire
Parcourir par canal
Automatisation
Les dernières nouveautés en matière d'automatisation informatique pour les technologies, les équipes et les environnements
Intelligence artificielle
Actualité sur les plateformes qui permettent aux clients d'exécuter des charges de travail d'IA sur tout type d'environnement
Cloud hybride ouvert
Découvrez comment créer un avenir flexible grâce au cloud hybride
Sécurité
Les dernières actualités sur la façon dont nous réduisons les risques dans tous les environnements et technologies
Edge computing
Actualité sur les plateformes qui simplifient les opérations en périphérie
Infrastructure
Les dernières nouveautés sur la plateforme Linux d'entreprise leader au monde
Applications
À l’intérieur de nos solutions aux défis d’application les plus difficiles
Programmes originaux
Histoires passionnantes de créateurs et de leaders de technologies d'entreprise
Produits
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Services cloud
- Voir tous les produits
Outils
- Formation et certification
- Mon compte
- Assistance client
- Ressources développeurs
- Rechercher un partenaire
- Red Hat Ecosystem Catalog
- Calculateur de valeur Red Hat
- Documentation
Essayer, acheter et vendre
Communication
- Contacter le service commercial
- Contactez notre service clientèle
- Contacter le service de formation
- Réseaux sociaux
À propos de Red Hat
Premier éditeur mondial de solutions Open Source pour les entreprises, nous fournissons des technologies Linux, cloud, de conteneurs et Kubernetes. Nous proposons des solutions stables qui aident les entreprises à jongler avec les divers environnements et plateformes, du cœur du datacenter à la périphérie du réseau.
Sélectionner une langue
Red Hat legal and privacy links
- À propos de Red Hat
- Carrières
- Événements
- Bureaux
- Contacter Red Hat
- Lire le blog Red Hat
- Diversité, équité et inclusion
- Cool Stuff Store
- Red Hat Summit