Chapter 7. Creating and uploading a customized RHEL system image to GCP using Red Hat Image Builder

The ability to create customized RHEL system images by using Red Hat Image Builder and upload those images to the Google Cloud Platform target environment is available.

7.1. Creating a customized RHEL system image for Google Cloud Platform using Red Hat Image Builder

You can create customized system images by using Red Hat Image Builder and upload those images to Google Cloud Platform so that you can start an instance from the image you uploaded.

Prerequisites

  • You have a valid Google account to share the image with.
  • You have a Red Hat account. Access Portal.
  • You have access to the Red Hat Image Builder.

Procedure

  1. Access Red Hat Image Builder on the browser of your preference.
  2. Click the Create image button.
  3. In the Image output window:

    1. From the dropdown menu, select the Release: Red Hat Enterprise Linux (RHEL) 8.3.
    2. Select Google Cloud Platform as the Target environment.

      Click Next.

  4. In the Target environment- Google Cloud Platform window, select a valid account type to share your image with, and Google account, Service account or domain name.

    • Google account: A Google account which interacts with Google Cloud, for example: alice@gmail.com.
    • Service account: An application account, for example: myapp@appspot.gserviceaccount.com.
    • Google group: A named collection of Google accounts and service accounts, for example: admins@example.com.
    • Google workspace domain/Cloud identity domain: A virtual group of all the Google accounts in a named organization. For example, the domain name mycompany.com.
  5. Enter the account email address or domain name, depending on the type of target environment you chose.

    Click Next.

  6. Un the Registration window, you have the option to:

  7. Optional: In the Additional package window, add packages to your image. See Chapter 4, Adding packages during image creation by Using Red Hat Image Builder.
  8. In the Review window, review the details about the image creation and click Create.

    Red Hat Image Builder starts to compose the RHEL 8.3 image for the x86_64 architecture and upload it to Google Cloud Platform. Then, it will share the image with the account you specified.

    You are redirected to the Red Hat Image Builder Images dashboard, where you can see details such as, the Image UUID, the cloud target environment, the image OS release and the status of the image creation. After the status is Ready, Red Hat Image Builder shares the image with the account you specified.

    Possible statuses:

    • Pending: the image upload and cloud registration is being processed.
    • In Progress: the image upload and cloud registration is ongoing.
    • Ready: the image upload and cloud registration is completed
    • Failed: the image upload and cloud registration failed.

      Note

      The image build, upload and cloud registration processes can take up to ten minutes to complete.

Verification

  • Check the status in the Images Dashboard. Click the image name to expand and show details.

    • The Ready status indicates that the image has been successfully created and shared with to the Google account.

      • In addition, the window shows the number of days until image expiration.
    • You can check which account the image is shared with.

7.2. Creating a VM instance using your GCE image

After the image is built, uploaded and the cloud registration process status is marked as Ready, you can create a Virtual Machine (VM) instance using the GCE image.

Prerequisites

  • You have the universally unique identifier (UUID) of the image you created.
  • You have access to the Image-builder service API endpoint.
  • You have access to your project details at Google Cloud Platform.
  • You can access Google Cloud Shell from your browser.

Procedure

  1. From the Red Hat Image Builder dashboard, copy the image UUID of the image you created.
  2. Access /composes/{composeId} API endpoint.
  3. Click the Try it Out button to activate the composeId string path.
  4. Enter the UUID into the composes/{composeId} field in the API endpoint.
  5. Click Execute. The API endpoint generates a response in the Response body, for example:

    {
      "image_status": {
        "status": "success",
        "upload_status": {
          "options": {
            "image_name": "composer-api-03f0e19c-0050-4c8a-a69e-88790219b086",
            "project_id": "red-hat-image-builder"
          },
          "status": "success",
          "type": "gcp"
        }
      }
    }
  6. From the Response body field, copy the image_name and project_id to access the image from the Google Cloud Platform environment.
  7. From your browser, access Google Cloud Shell.
  8. Set your Google Cloud Platform Project ID as the default GCP project. You can find the Product ID of your project by accessing the Google Cloud Platform dashboard.

    $ gcloud config set project PROJECT_ID
  9. In the Authorize Cloud Shell window prompt, click Authorize to allow this and future calls that require your credentials.
  10. Create a VM instance with the image by using the gcloud command in the Google Cloud Shell:

    $ gcloud compute instances create INSTANCE_NAME \
      --image-project PROJECT_ID_FROM_RESPONSE \
      --image IMAGE_NAME \
      --zone GCP_ZONE

    Where:

    • INSTANCE_NAME is the name you give to your instance;
    • PROJECT_ID_FROM_RESPONSE is the project_id generated by Response body;
    • IMAGE_NAME is the image_name generated by Response body;
    • GCP_ZONE is the GCP zone in which the instance will be created.

Verification

  1. Verify that Compute Engine created the VM:

    $ gcloud compute instances describe INSTANCE_NAME
  2. Connect to the VM instance via SSH:

    $ gcloud compute ssh --project=PROJECT_ID --zone=ZONE INSTANCE_NAME

7.3. Copying the GCE image to your project group

After the image is built, uploaded and the cloud registration process status is marked as Ready, you can create a Virtual Machine (VM) instance using the GCE image.

Prerequisites

  • The universally unique identifier (UUID) of the image you created.
  • Access to the Image-builder service API endpoint.
  • Access to the Google Cloud Shell from your browser.

Procedure

  1. From the Image Builder dashboard, copy the UUID image of the image you created.
  2. Access /composes/{composeId} API endpoint.
  3. Click the Try it Out button to activate the composeId string path.
  4. Enter the UUID into the composes/{composeId} field in the API endpoint.
  5. Click Execute. The API endpoint generates a response in the Response body, for example:

    {
      "image_status": {
        "status": "success",
        "upload_status": {
          "options": {
            "image_name": "composer-api-03f0e19c-0050-4c8a-a69e-88790219b086",
            "project_id": "red-hat-image-builder"
          },
          "status": "success",
          "type": "gcp"
        }
      }
    }
  6. From the Response body field, copy the image_name and project_id to access the image from the Google Cloud Platform environment.
  7. From your browser, access Google Cloud Shell.
  8. Set your Google Cloud Platform Project ID as the default GCP project. You can find the Product ID of your project by accessing the Google Cloud Platform dashboard.

    $ gcloud config set project PROJECT_ID
  9. In the Authorize Cloud Shell window prompt, click Authorize to allow this and future calls that require your credentials.
  10. Copy the image to your project by using the gcloud command:

    $ gcloud compute images create MY_IMAGE_NAME \
      --source-image-project PROJECT_ID_FROM_RESPONSE \
      --source-image IMAGE_NAME

    Where:

    • MY_IMAGE_NAME is the name you give to your instance;
    • PROJECT_ID_FROM_RESPONSE is the project_id generated by Response body;
    • IMAGE_NAME is the image_name generated by Response body;

Verification

Confirm that the image has been successfully copied to your project:

  • Using the Google Cloud Platform UI, by accessing the Compute Engine / Images section.
  • Using the gcloud tool, by running the command in Google Cloud Shell:

    $ gcloud compute images list --no-standard-images

Additional resources