Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 3. Deploying a Red Hat Enterprise Linux image as a Google Compute Engine instance on Google Cloud Platform
To set up a deployment of Red Hat Enterprise Linux 8 (RHEL 8) on Google Cloud Platform (GCP), you can deploy RHEL 8 as a Google Compute Engine (GCE) instance on GCP.
For a list of Red Hat product certifications for GCP, see Red Hat on Google Cloud Platform.
You can create a custom VM from an ISO image, but Red Hat recommends that you use the Red Hat Image Builder product to create customized images for use on specific cloud providers. See Composing a Customized RHEL System Image for more information.
Prerequisites
- You need a Red Hat Customer Portal account to complete the procedures in this chapter.
- Create an account with GCP to access the Google Cloud Platform Console. See Google Cloud for more information.
3.1. Red Hat Enterprise Linux image options on GCP Copier lienLien copié sur presse-papiers!
You can use multiple types of images for deploying RHEL 8 on Google Cloud Platform. Based on your requirements, consider which option is optimal for your use case.
| Image option | Subscriptions | Sample scenario | Considerations |
|---|---|---|---|
| Deploy a Red Hat Gold Image. | Use your existing Red Hat subscriptions. | Select a Red Hat Gold Image on Google Cloud Platform. For details on Gold Images and how to access them on Google Cloud Platform, see the Red Hat Cloud Access Reference Guide. | The subscription includes the Red Hat product cost; you pay Google for all other instance costs. Red Hat provides support directly for custom RHEL images. |
| Deploy a custom image that you move to GCP. | Use your existing Red Hat subscriptions. | Upload your custom image and attach your subscriptions. | The subscription includes the Red Hat product cost; you pay all other instance costs. Red Hat provides support directly for custom RHEL images. |
| Deploy an existing GCP image that includes RHEL. | The GCP images include a Red Hat product. | Choose a RHEL image when you launch an instance on the GCP Compute Engine, or choose an image from the Google Cloud Platform Marketplace. | You pay GCP hourly on a pay-as-you-go model. Such images are called "on-demand" images. GCP offers support for on-demand images through a support agreement. |
You can create a custom image for GCP by using Red Hat Image Builder. See Composing a Customized RHEL System Image for more information.
You cannot convert an on-demand instance to a custom RHEL instance. To change from an on-demand image to a custom RHEL bring-your-own-subscription (BYOS) image:
- Create a new custom RHEL instance and migrate data from your on-demand instance.
- Cancel your on-demand instance after you migrate your data to avoid double billing.
3.2. Understanding base images Copier lienLien copié sur presse-papiers!
To create a base VM from an ISO image, you can use preconfigured base images and their configuration settings.
3.2.1. Using a custom base image Copier lienLien copié sur presse-papiers!
To manually configure a virtual machine (VM), first create a base (starter) VM image. Then, you can modify configuration settings and add the packages the VM requires to operate on the cloud. You can make additional configuration changes for your specific application after you upload the image.
3.2.2. Virtual machine configuration settings Copier lienLien copié sur presse-papiers!
Cloud VMs must have the following configuration settings.
| Setting | Recommendation |
|---|---|
| ssh | ssh must be enabled to provide remote access to your VMs. |
| dhcp | The primary virtual adapter should be configured for dhcp. |
3.3. Creating a base VM from an ISO image Copier lienLien copié sur presse-papiers!
To create a RHEL 8 base image from an ISO image, enable your host machine for virtualization and create a RHEL virtual machine (VM).
Prerequisites
- Virtualization is enabled on your host machine.
-
You have downloaded the latest Red Hat Enterprise Linux ISO image from the Red Hat Customer Portal and moved the image to
/var/lib/libvirt/images.
3.3.1. Creating a VM from the RHEL ISO image Copier lienLien copié sur presse-papiers!
Procedure
- Ensure that you have enabled your host machine for virtualization. See Enabling virtualization in RHEL 8 for information and procedures.
Create and start a basic Red Hat Enterprise Linux VM. For instructions, see Creating virtual machines.
If you use the command line to create your VM, ensure that you set the default memory and CPUs to the capacity you want for the VM. Set your virtual network interface to virtio.
For example, the following command creates a
kvmtestVM by using the/home/username/Downloads/rhel8.isoimage:virt-install \ --name kvmtest --memory 2048 --vcpus 2 \ --cdrom /home/username/Downloads/rhel8.iso,bus=virtio \ --os-variant=rhel8.0# virt-install \ --name kvmtest --memory 2048 --vcpus 2 \ --cdrom /home/username/Downloads/rhel8.iso,bus=virtio \ --os-variant=rhel8.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you use the web console to create your VM, follow the procedure in Creating virtual machines by using the web console, with these caveats:
- Do not check Immediately Start VM.
- Change your Memory size to your preferred settings.
- Before you start the installation, ensure that you have changed Model under Virtual Network Interface Settings to virtio and change your vCPUs to the capacity settings you want for the VM.
3.3.2. Completing the RHEL installation Copier lienLien copié sur presse-papiers!
To finish the installation of a RHEL system that you want to deploy on Amazon Web Services (AWS), customize the Installation Summary view, begin the installation, and enable root access once the VM launches.
Procedure
- Choose the language you want to use during the installation process.
On the Installation Summary view:
- Click Software Selection and check Minimal Install.
- Click Done.
Click Installation Destination and check Custom under Storage Configuration.
-
Verify at least 500 MB for
/boot. You can use the remaining space for root/. - Standard partitions are recommended, but you can use Logical Volume Manager (LVM).
- You can use xfs, ext4, or ext3 for the file system.
- Click Done when you are finished with changes.
-
Verify at least 500 MB for
- Click Begin Installation.
- Set a Root Password. Create other users as applicable.
-
Reboot the VM and log in as
rootonce the installation completes. Configure the image.
Register the VM and enable the Red Hat Enterprise Linux 8 repository.
subscription-manager register
# subscription-manager registerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the
cloud-initpackage is installed and enabled.yum install cloud-init systemctl enable --now cloud-init.service
# yum install cloud-init # systemctl enable --now cloud-init.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
- Power off the VM.
3.4. Uploading the RHEL image to GCP Copier lienLien copié sur presse-papiers!
To run your RHEL 8 instance on Google Cloud Platform (GCP), you must upload your RHEL 8 image to GCP.
3.4.1. Creating a new project on GCP Copier lienLien copié sur presse-papiers!
To upload your Red Hat Enterprise Linux 8 image to Google Cloud Platform (GCP), you must first create a new project on GCP.
Prerequisites
- You must have an account with GCP. If you do not, see Google Cloud for more information.
Procedure
- Launch the GCP Console.
- Click the drop-down menu to the right of Google Cloud Platform.
- From the pop-up menu, click NEW PROJECT.
- From the New Project window, enter a name for your new project.
- Check Organization. Click the drop-down menu to change the organization, if necessary.
- Confirm the Location of your parent organization or folder. Click Browse to search for and change this value, if necessary.
Click CREATE to create your new GCP project.
NoteOnce you have installed the Google Cloud SDK, you can use the
gcloud projects createCLI command to create a project. For example:gcloud projects create my-gcp-project3 --name project3
# gcloud projects create my-gcp-project3 --name project3Copy to Clipboard Copied! Toggle word wrap Toggle overflow The example creates a project with the project ID
my-gcp-project3and the project nameproject3. See gcloud project create for more information.
3.4.2. Installing the Google Cloud SDK Copier lienLien copié sur presse-papiers!
Many of the procedures to manage HA clusters on Google Cloud Platform (GCP) require the tools in the Google Cloud SDK.
Procedure
- Follow the GCP instructions for downloading and extracting the Google Cloud SDK archive. See the GCP document Quickstart for Linux for details.
Follow the same instructions for initializing the Google Cloud SDK.
NoteOnce you have initialized the Google Cloud SDK, you can use the
gcloudCLI commands to perform tasks and obtain information about your project and instances. For example, you can display project information with thegcloud compute project-info describe --project <project-name>command.
3.4.3. Creating SSH keys for Google Compute Engine Copier lienLien copié sur presse-papiers!
Generate and register SSH keys with GCE so that you can SSH directly into an instance by using its public IP address.
Procedure
Use the
ssh-keygencommand to generate an SSH key pair for use with GCE.ssh-keygen -t rsa -f ~/.ssh/google_compute_engine
# ssh-keygen -t rsa -f ~/.ssh/google_compute_engineCopy to Clipboard Copied! Toggle word wrap Toggle overflow - From the GCP Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Metadata.
- Click SSH Keys and then click Edit.
Enter the output generated from the
~/.ssh/google_compute_engine.pubfile and click Save.You can now connect to your instance by using standard SSH.
ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>
# ssh -i ~/.ssh/google_compute_engine <username>@<instance_external_ip>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
You can run the gcloud compute config-ssh command to populate your config file with aliases for your instances. The aliases allow simple SSH connections by instance name. For information about the gcloud compute config-ssh command, see gcloud compute config-ssh.
3.4.4. Creating a storage bucket in GCP Storage Copier lienLien copié sur presse-papiers!
To import your RHEL 8 image to GCP, you must first create a GCP Storage Bucket.
Procedure
If you are not already logged in to GCP, log in with the following command.
gcloud auth login
# gcloud auth loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a storage bucket.
gsutil mb gs://bucket_name
# gsutil mb gs://bucket_nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAlternatively, you can use the Google Cloud Console to create a bucket. See Create a bucket for information.
3.4.5. Converting and uploading your image to your GCP Bucket Copier lienLien copié sur presse-papiers!
Before a local RHEL 8 image can be deployed in GCP, you must first convert and upload the image to your GCP Bucket. The following steps describe converting an qcow2 image to raw format and then uploading the image as a tar archive. However, using different formats is possible as well.
Procedure
Run the
qemu-imgcommand to convert your image. The converted image must have the namedisk.raw.qemu-img convert -f qcow2 -O raw rhel-8.0-sample.qcow2 disk.raw
# qemu-img convert -f qcow2 -O raw rhel-8.0-sample.qcow2 disk.rawCopy to Clipboard Copied! Toggle word wrap Toggle overflow Tar the image.
tar --format=oldgnu -Sczf disk.raw.tar.gz disk.raw
# tar --format=oldgnu -Sczf disk.raw.tar.gz disk.rawCopy to Clipboard Copied! Toggle word wrap Toggle overflow Upload the image to the bucket you created previously. Upload could take a few minutes.
gsutil cp disk.raw.tar.gz gs://bucket_name
# gsutil cp disk.raw.tar.gz gs://bucket_nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow - From the Google Cloud Platform home screen, click the collapsed menu icon and select Storage and then select Browser.
Click the name of your bucket.
The tarred image is listed under your bucket name.
NoteYou can also upload your image by using the GCP Console. To do so, click the name of your bucket and then click Upload files.
3.4.6. Creating an image from the object in the GCP bucket Copier lienLien copié sur presse-papiers!
Before you can create a GCE image from an object that you uploaded to your GCP bucket, you must convert the object into a GCE image.
Procedure
Run the following command to create an image for GCE. Specify the name of the image you are creating, the bucket name, and the name of the tarred image.
gcloud compute images create my-image-name --source-uri gs://my-bucket-name/disk.raw.tar.gz
# gcloud compute images create my-image-name --source-uri gs://my-bucket-name/disk.raw.tar.gzCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAlternatively, you can use the Google Cloud Console to create an image. See Creating, deleting, and deprecating custom images for more information.
Optional: Find the image in the GCP Console.
- Click the Navigation menu to the left of the Google Cloud Console banner.
- Select Compute Engine and then Images.
3.4.7. Creating a Google Compute Engine instance from an image Copier lienLien copié sur presse-papiers!
To configure a GCE VM instance from an image, use the GCP Console.
See Creating and starting a VM instance for more information about GCE VM instances and their configuration options.
Procedure
- From the GCP Console Dashboard page, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select Images.
- Select your image.
- Click Create Instance.
- On the Create an instance page, enter a Name for your instance.
- Choose a Region and Zone.
- Choose a Machine configuration that meets or exceeds the requirements of your workload.
- Ensure that Boot disk specifies the name of your image.
- Optional: Under Firewall, select Allow HTTP traffic or Allow HTTPS traffic.
Click Create.
NoteThese are the minimum configuration options necessary to create a basic instance. Review additional options based on your application requirements.
- Find your image under VM instances.
From the GCP Console Dashboard, click the Navigation menu to the left of the Google Cloud Console banner and select Compute Engine and then select VM instances.
NoteAlternatively, you can use the
gcloud compute instances createCLI command to create a GCE VM instance from an image. A simple example follows.gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-image
gcloud compute instances create myinstance3 --zone=us-central1-a --image test-iso2-imageCopy to Clipboard Copied! Toggle word wrap Toggle overflow The example creates a VM instance named
myinstance3in zoneus-central1-abased upon the existing imagetest-iso2-image. See gcloud compute instances create for more information.
3.4.8. Connecting to your instance Copier lienLien copié sur presse-papiers!
Connect to your GCE instance by using its public IP address.
Procedure
Ensure that your instance is running. The following command lists information about your GCE instance, including whether the instance is running, and, if so, the public IP address of the running instance.
gcloud compute instances list
# gcloud compute instances listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Connect to your instance by using standard SSH. The example uses the
google_compute_enginekey created earlier.ssh -i ~/.ssh/google_compute_engine <user_name>@<instance_external_ip>
# ssh -i ~/.ssh/google_compute_engine <user_name>@<instance_external_ip>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteGCP offers a number of ways to SSH into your instance. See Connecting to instances for more information. You can also connect to your instance using the root account and password you set previously.
3.4.9. Attaching Red Hat subscriptions Copier lienLien copié sur presse-papiers!
Using the subscription-manager command, you can register and attach your Red Hat subscription to a RHEL instance.
Prerequisites
- You must have enabled your subscriptions.
Procedure
Register your system.
subscription-manager register
# subscription-manager registerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Attach your subscriptions.
- You can use an activation key to attach subscriptions. See Creating Red Hat Customer Portal Activation Keys for more information.
- Also, you can manually attach a subscription by using the ID of subscription pool (Pool ID). See Attaching a host-based subscription to hypervisors.
Optional: To collect various system metrics about the instance in the Red Hat Hybrid Cloud Console, you can register the instance with Red Hat Insights.
insights-client register --display-name <display_name_value>
# insights-client register --display-name <display_name_value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For information about further configuration of Red Hat Insights, see Client Configuration Guide for Red Hat Insights.