Dark Light

Introduction

In GCP it’s common to work with custom images. It is easy to create an image. It becomes a bit more complex as soon as it needs to be converted from another source and especially if the application needs to have nested virtualization enabled.

Prerequisites

  • Linux System (can be VM)
  • Access to GCP console with permission to:
    • create Buckets
    • create Images
    • create Virtual Instances
  • Basic GCP / Linux knowledge

Convert raw image

Upload image to Linux System and use the following command to convert the VMDK file to RAW:

qemu-img dd -f vmdk -O raw bs=4M count=1K if=<image>.vmdk of=<image>.raw
tar -cvzf <image>.tar.gz <image>.raw

Create Storage Bucket

gcloud storage buckets create gs://<bucket-name> \
--project=<project-id> \
--default-storage-class=STANDARD \
--location=EUROPE-WEST6 \
--uniform-bucket-level-access

Upload .tar.gz file to Bucket

Upload file to bucket

Create image from storage bucket

gcloud compute images create as-image1 \
--project=<project-id> \
--source-uri gs://<bucket-name>/<filename>.tar.gz \
--licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx" \
--family <os-app-family>

Create virtual machine from image

Important in this step is to select n1* machine type, since newer generations don’t necessarily support nested virtualization.

gcloud compute instances create as-image-vm1 \
--project=<project-id> \
--zone=europe-west6-a \
--machine-type=n1-standard-16  \
--network-interface=network-tier=PREMIUM,subnet=default \
--create-disk=auto-delete=yes,boot=yes,device-name=as-fortipoc3,image=projects/se-projects-242100/global/images/as-image1-8,mode=rw,size=100,type=projects/<project-id>/zones/europe-west6-a/diskTypes/pd-ssd

Leave a Reply

Your email address will not be published. Required fields are marked *