Ubuntu 24.04 LTS OS image import reference implementation on GDC air-gapped

This document provides step-by-step instructions for customizing an Ubuntu 24.04 LTS KVM cloud image (noble-server-cloudimg-amd64.img) offline, optionally pre-baking workload packages (such as postgresql-17 or nfs-kernel-server), and importing it into a Google Distributed Cloud (GDC) air-gapped tenant project with VirtualMachineImageImport. Completing this component implementation produces a reusable project-scoped VirtualMachineImage resource and writes the isolated environment contract ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/env.d/linux-vm-images.sh consumed by downstream database, storage, and application guides.

Tested releases

Distribution Minor release GDC air-gapped target Status Notes
Ubuntu 24.04 LTS (noble) 1.16.2-hf1 (1.16.2-gdch.1353-1) Tested Offline virt-customize preparation and VirtualMachineImageImport (operatingSystem: ubuntu-2404, prepareImage: false) with optional pre-baked postgresql-17 and nfs-kernel-server.

Before you begin

Environment configuration

Before you import images or create VMs, configure the required GDC Identity and Access Management (IAM) roles, workstation tools, and environment variables.

Identity and Access Management

To get the permissions that you need to import custom OS images and verify SSH access, ask your IAM Project Admin to grant you the following roles in your project namespace on the management API server:

  • Project Viewer (project-viewer)
  • Virtual Machine Project Admin (project-vm-admin)
  • Virtual Machine Image Project Admin (project-vm-image-admin)
  • Bucket Object Project Admin (project-bucket-object-admin)
  • Project Network Policy Admin (project-networkpolicy-admin)

Workstation requirements

The following command-line utilities and source artifacts must be available on a connected build workstation (for offline image customization) and on the deployment workstation inside the air-gapped zone:

  • gdcloud CLI: command-line tool for managing GDC air-gapped resources, with the storage-cli-dependencies component installed.
  • kubectl CLI: command-line tool for interacting with the management API server.
  • libguestfs-tools: Offline image customization tools (virt-customize, virt-cat, virt-inspector). If /dev/kvm or libvirtd is unavailable on the build host, export LIBGUESTFS_BACKEND=direct. On Ubuntu and Debian workstations running LIBGUESTFS_BACKEND=direct, libguestfs (supermin) requires an installed host kernel (linux-image-generic on Ubuntu or linux-image-amd64 on Debian) and read access to /boot/vmlinuz*. Ubuntu installs /boot/vmlinuz* with 0600 (root-only) permissions. Allow the current user to read the kernel image with sudo setfacl -m "u:${USER}:r" /boot/vmlinuz* (from the acl package) so that unprivileged virt-customize and virt-cat commands can locate a libguestfs appliance.
  • qemu-utils: QEMU disk utilities (qemu-img) for inspecting and resizing raw/qcow2 images.
  • openssh-client: OpenSSH client utilities (ssh-keygen, ssh) for administrative key generation and SSH verification.
  • sha256sum: Coreutils checksum verification utility.
  • noble-server-cloudimg-amd64.img: Official Ubuntu 24.04 LTS (noble) AMD64 KVM cloud image downloaded from Ubuntu Cloud Images.

Workstation configuration

  1. Create the root solution directories and secrets folder:

    mkdir -p ${HOME}/gdcag-solutions/env.d
    mkdir -p ${HOME}/gdcag-solutions/secrets
    
    touch ${HOME}/gdcag-solutions/secrets/harbor_crane_robot_token
    touch ${HOME}/gdcag-solutions/secrets/harbor_k8s_robot_token
    
    chmod u=rwx,go= ${HOME}/gdcag-solutions/secrets
    chmod -R u=rw,go= ${HOME}/gdcag-solutions/secrets/*
    
  2. Create the platform environment configuration file:

    cat << 'EOF' > ${HOME}/gdcag-solutions/env.d/platform.sh && echo "Successfully created." || echo "Failed to create!"
    # Infrastructure (Platform Native)
    export GDC_DOMAIN_SUFFIX="DOMAIN_SUFFIX"
    export GDC_ORG="ORG"
    export GDC_PROJECT="PROJECT"
    export GDC_ZONE="ZONE"
    export GDC_HARBOR_INSTANCE_NAME="HARBOR_INSTANCE_NAME"
    
    # Derived platform values
    export GDC_ZONAL_HOSTNAME="${GDC_ORG}.${GDC_ZONE}.${GDC_DOMAIN_SUFFIX}"
    export GDC_ZONAL_CONSOLE_URL="https://console.${GDC_ZONAL_HOSTNAME}"
    export GDC_HARBOR_HOST="${GDC_HARBOR_INSTANCE_NAME}-${GDC_PROJECT}.${GDC_ORG}.${GDC_ZONE}.${GDC_DOMAIN_SUFFIX}"
    EOF
    

    Replace the following:

    • DOMAIN_SUFFIX: GDC domain suffix.
    • ORG: GDC organization.
    • PROJECT: GDC project.
    • ZONE: GDC zone.
    • HARBOR_INSTANCE_NAME: GDC Harbor instance name.
  3. Create the registry environment configuration file:

    cat << 'EOF' > ${HOME}/gdcag-solutions/env.d/registry.sh && echo "Successfully created." || echo "Failed to create!"
    # GDC Solutions Registry & Secrets
    export GDCS_HARBOR_PROJECT_NAME="solutions"
    export GDCS_HARBOR_CRANE_ROBOT_NAME='HARBOR_CRANE_ROBOT_NAME'
    export GDCS_HARBOR_CRANE_ROBOT_TOKEN="$(cat ${GDCS_ROOT_HOME}/secrets/harbor_crane_robot_token)"
    export GDCS_HARBOR_K8S_ROBOT_NAME='HARBOR_K8S_ROBOT_NAME'
    export GDCS_HARBOR_K8S_ROBOT_TOKEN="$(cat ${GDCS_ROOT_HOME}/secrets/harbor_k8s_robot_token)"
    export GDCS_HARBOR_K8S_PULL_SECRET="gdcs-image-pull-secret"
    
    # Derived registry values
    export GDCS_HARBOR_PROJECT_URI="${GDC_HARBOR_HOST}/${GDCS_HARBOR_PROJECT_NAME}"
    export GDCS_HARBOR_CHART_OCI_URI="oci://${GDCS_HARBOR_PROJECT_URI}"
    EOF
    

    Replace the following:

    • HARBOR_CRANE_ROBOT_NAME: the full name of the Harbor robot account for crane, as Harbor shows it, including the robot$ prefix. Keep the single quotes so that the shell doesn't expand $.
    • HARBOR_K8S_ROBOT_NAME: the full name of the Harbor robot account for Kubernetes image pulls, as Harbor shows it, including the robot$ prefix. Keep the single quotes so that the shell doesn't expand $.
  4. Create the root environment loader file:

    cat << 'EOF' > ${HOME}/gdcag-solutions/env.sh && echo "Successfully created." || echo "Failed to create!"
    export GDCS_ROOT_HOME="${HOME}/gdcag-solutions"
    echo "GDCS_ROOT_HOME=${GDCS_ROOT_HOME}"
    
    # Sourced in dependency order
    source "${GDCS_ROOT_HOME}/env.d/platform.sh"
    source "${GDCS_ROOT_HOME}/env.d/registry.sh"
    EOF
    

Configure solution variables

  1. Create the isolated implementation directory structure for Ubuntu OS images and restrict permissions on the secrets directory:

    mkdir -p ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/env.d
    mkdir -p ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/images
    mkdir -p ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/manifests
    mkdir -p ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/secrets
    chmod u=rwx,go= ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/secrets
    
  2. Create the Ubuntu Linux VM images environment contract file env.d/linux-vm-images.sh inside the component directory:

    cat << 'EOF' > ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/env.d/linux-vm-images.sh && echo "Successfully created." || echo "Failed to create!"
    # Shared Ubuntu Linux VM Images Contract
    export GDCS_VM_IMAGES_BUCKET="vm-images-bucket"
    export GDCS_UBUNTU2404_IMAGE_NAME="ubuntu-2404-custom"
    export GDCS_UBUNTU2404_IMAGE_MIN_DISK_SIZE="20Gi"
    export GDCS_UBUNTU2404_IMAGE_OS="ubuntu-2404"
    export GDCS_UBUNTU2404_QCOW2_FILE="${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/images/noble-server-cloudimg-amd64.img"
    export GDCS_UBUNTU2404_BAKED_QCOW2_FILE="${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/images/noble-server-cloudimg-amd64-baked.qcow2"
    export GDCS_UBUNTU2404_DISK_EXPAND="+3G"
    export GDCS_UBUNTU2404_EXTRA_PACKAGES="UBUNTU2404_EXTRA_PACKAGES"
    export GDCS_UBUNTU2404_ADD_PGDG_REPO="UBUNTU2404_ADD_PGDG_REPO"
    
    export GDCS_VM_ADMIN_USER="ubuntu"
    export GDCS_VM_ADMIN_SSH_KEY_FILE="${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/secrets/ubuntu_admin_ed25519"
    export GDCS_GDC_NTP_SERVERS="ntp1.org.internal ntp2.org.internal"
    
    # Verification and Test VM Variables
    export GDCS_TEST_VM_NAME="ubuntu-test-vm"
    export GDCS_TEST_VM_MACHINE_TYPE="n3-standard-2-gdc"
    export GDCS_TEST_VM_BOOT_DISK_SIZE="22GB"
    export GDCS_TEST_VM_ADMIN_CIDR="TEST_VM_ADMIN_CIDR"
    export GDCS_TEST_VM_SSH_PNP_NAME="allow-test-vm-ssh"
    export GDCS_TEST_VM_INGRESS_IP=""
    
    export GDC_MANAGEMENT_API_SERVER="${GDC_ORG}-admin"
    export GDC_MANAGEMENT_API_KUBECONFIG="${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/${GDC_MANAGEMENT_API_SERVER}-kubeconfig.yaml"
    EOF
    

    Replace the following:

    • UBUNTU2404_EXTRA_PACKAGES: optional space-separated apt packages to bake offline (for example, nfs-kernel-server or postgresql-17 postgresql-client-17), or an empty string ("") if you don't need extra packages.
    • UBUNTU2404_ADD_PGDG_REPO: true when baking postgresql-17 from the PostgreSQL Global Development Group (PGDG) repository, or false otherwise.
    • TEST_VM_ADMIN_CIDR: the workstation or administrative IPv4 CIDR block (for example, 10.0.0.0/8).
  3. Create the implementation loader script:

    cat << 'EOF' > ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/env.sh && echo "Successfully created." || echo "Failed to create!"
    source "${HOME}/gdcag-solutions/env.sh"
    
    export GDCS_IMPLEMENTATION_HOME="${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu"
    echo "GDCS_IMPLEMENTATION_HOME=${GDCS_IMPLEMENTATION_HOME}"
    
    source "${GDCS_IMPLEMENTATION_HOME}/env.d/linux-vm-images.sh"
    EOF
    
  4. Source the environment file. You must source this environment file in every new shell session:

    source ${HOME}/gdcag-solutions/components/custom-linux-os-images/ubuntu/env.sh
    

    The output is similar to the following:

    GDCS_ROOT_HOME=HOME_DIRECTORY_PATH/gdcag-solutions
    GDCS_IMPLEMENTATION_HOME=HOME_DIRECTORY_PATH/gdcag-solutions/components/custom-linux-os-images/ubuntu
    
  5. Generate an ED25519 SSH key pair for the virtual machine administrative user if one doesn't already exist:

    if [[ ! -f "${GDCS_VM_ADMIN_SSH_KEY_FILE}" ]]; then
      ssh-keygen \
      -C "ubuntu@gdc-vm" \
      -N "" \
      -f "${GDCS_VM_ADMIN_SSH_KEY_FILE}" \
      -t ed25519
    fi
    
    chmod u=rw,go= "${GDCS_VM_ADMIN_SSH_KEY_FILE}"*
    
  6. Store the temporary emergency password for serial console recovery in a restricted (0600) secret file:

    chmod u=rwx,go= "${GDCS_IMPLEMENTATION_HOME}/secrets"
    install -m 600 /dev/null "${GDCS_IMPLEMENTATION_HOME}/secrets/vm_admin_password"
    set +o history
    printf '%s' 'VM_ADMIN_PASSWORD' > "${GDCS_IMPLEMENTATION_HOME}/secrets/vm_admin_password"
    set -o history
    

    Replace VM_ADMIN_PASSWORD with a temporary emergency password for serial console recovery. Keep the single quotes so that the shell doesn't expand special characters such as $, backticks, \`, or!(if your password includes a single quote, prompt for it withIFS= read -r -s` instead).

Prepare the Ubuntu 24.04 image offline

  1. Download the official Ubuntu 24.04 LTS cloud image and verify its SHA-256 checksum against the upstream SHA256SUMS manifest:

    curl --fail --location --output "${GDCS_UBUNTU2404_QCOW2_FILE}" \
    "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
    
    curl --fail --location --output "${GDCS_IMPLEMENTATION_HOME}/images/SHA256SUMS" \
    "https://cloud-images.ubuntu.com/noble/current/SHA256SUMS"
    
    grep "noble-server-cloudimg-amd64.img" "${GDCS_IMPLEMENTATION_HOME}/images/SHA256SUMS" | \
    sed "s|noble-server-cloudimg-amd64.img|${GDCS_UBUNTU2404_QCOW2_FILE}|" | \
    sha256sum --check -
    
  2. Inspect the virtual size of the pristine Ubuntu 24.04 cloud image, copy it to the baked output file, and expand the virtual disk so offline apt-get install operations have sufficient headroom:

    qemu-img info "${GDCS_UBUNTU2404_QCOW2_FILE}"
    
    cp "${GDCS_UBUNTU2404_QCOW2_FILE}" "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}"
    qemu-img resize "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" "${GDCS_UBUNTU2404_DISK_EXPAND}"
    
  3. Generate the offline chrony.conf, cloud-init data source configuration, and an optional in-image package baking script:

    cat << EOF > "${GDCS_IMPLEMENTATION_HOME}/images/chrony.conf"
    # GDC air-gapped organization time servers (manual-mode import: not injected by the platform)
    $(for s in ${GDCS_GDC_NTP_SERVERS}; do echo "server ${s} iburst"; done)
    driftfile /var/lib/chrony/drift
    makestep 1.0 3
    rtcsync
    logdir /var/log/chrony
    EOF
    
    cat << 'EOF' > "${GDCS_IMPLEMENTATION_HOME}/images/99-gdc-datasource.cfg"
    # GDC provides a NoCloud seed (cloud-init runs startupScripts on every boot); pin the list so no external cloud datasources are probed
    datasource_list: [ NoCloud, None ]
    EOF
    
    cat << 'EOF' > "${GDCS_IMPLEMENTATION_HOME}/images/bake-ubuntu.sh"
    #!/usr/bin/env bash
    set -euo pipefail
    
    export DEBIAN_FRONTEND=noninteractive
    
    ROOT_PART=$(findmnt --noheadings --output SOURCE /)
    DISK_DEV="/dev/$(lsblk --noheadings --output PKNAME "${ROOT_PART}")"
    PART_NUM=$(cat "/sys/class/block/$(basename "${ROOT_PART}")/partition")
    growpart "${DISK_DEV}" "${PART_NUM}" || true
    resize2fs "${ROOT_PART}"
    
    apt-get update
    apt-get install --no-install-recommends --yes chrony qemu-guest-agent
    
    if [[ -n "${GDCS_UBUNTU2404_EXTRA_PACKAGES:-}" ]]; then
      if [[ "${GDCS_UBUNTU2404_ADD_PGDG_REPO:-false}" == "true" ]]; then
        apt-get install --no-install-recommends --yes ca-certificates curl gnupg postgresql-common
        mkdir -p /etc/postgresql-common/createcluster.d
        echo "create_main_cluster = false" > /etc/postgresql-common/createcluster.d/gdcs.conf
        /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
        apt-get update
      fi
    
      apt-get install --no-install-recommends --yes ${GDCS_UBUNTU2404_EXTRA_PACKAGES}
      systemctl disable nfs-server postgresql || true
    fi
    
    systemctl enable chrony ssh
    apt-get clean
    rm -rf /var/lib/apt/lists/*
    
    cloud-init clean --logs
    EOF
    chmod +x "${GDCS_IMPLEMENTATION_HOME}/images/bake-ubuntu.sh"
    
  4. Customize the Ubuntu 24.04 image offline with virt-customize to inject the administrative user, SSH public key, emergency password, chrony configuration, cloud-init data source settings, and any optional packages:

    export LIBGUESTFS_BACKEND="${LIBGUESTFS_BACKEND:-direct}"
    
    virt-customize \
    --add "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" \
    --run-command "id -u ${GDCS_VM_ADMIN_USER} >/dev/null 2>&1 || useradd --create-home --groups sudo --shell /bin/bash ${GDCS_VM_ADMIN_USER}" \
    --password "${GDCS_VM_ADMIN_USER}:file:${GDCS_IMPLEMENTATION_HOME}/secrets/vm_admin_password" \
    --ssh-inject "${GDCS_VM_ADMIN_USER}:file:${GDCS_VM_ADMIN_SSH_KEY_FILE}.pub" \
    --write "/etc/sudoers.d/${GDCS_VM_ADMIN_USER}:${GDCS_VM_ADMIN_USER} ALL=(ALL) NOPASSWD:ALL" \
    --chmod "0440:/etc/sudoers.d/${GDCS_VM_ADMIN_USER}" \
    --copy-in "${GDCS_IMPLEMENTATION_HOME}/images/99-gdc-datasource.cfg:/etc/cloud/cloud.cfg.d" \
    --upload "${GDCS_IMPLEMENTATION_HOME}/images/bake-ubuntu.sh:/tmp/bake-ubuntu.sh" \
    --run-command "GDCS_UBUNTU2404_ADD_PGDG_REPO='${GDCS_UBUNTU2404_ADD_PGDG_REPO}' GDCS_UBUNTU2404_EXTRA_PACKAGES='${GDCS_UBUNTU2404_EXTRA_PACKAGES}' bash /tmp/bake-ubuntu.sh" \
    --run-command "rm -f /tmp/bake-ubuntu.sh" \
    --upload "${GDCS_IMPLEMENTATION_HOME}/images/chrony.conf:/etc/chrony/chrony.conf" \
    --truncate /etc/machine-id
    
  5. Verify the SSH key, chrony configuration, cloud-init data source file, and disk footprint inside the customized image without booting a VM:

    virt-cat --add "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" "/home/${GDCS_VM_ADMIN_USER}/.ssh/authorized_keys" | cut -c1-40
    virt-cat --add "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" /etc/chrony/chrony.conf | head -3
    virt-cat --add "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" /etc/cloud/cloud.cfg.d/99-gdc-datasource.cfg
    qemu-img info "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" | grep -E 'virtual size|disk size'
    

    The output is similar to the following:

    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...
    server ntp1.org.internal iburst
    server ntp2.org.internal iburst
    datasource_list: [ NoCloud, None ]
    virtual size: 6.5 GiB (... bytes)
    

Import custom Ubuntu image into VM manager

Transfer ${GDCS_UBUNTU2404_BAKED_QCOW2_FILE} to your deployment workstation inside the air-gapped enclave if customization was performed on an external connected build host.

  1. Authenticate to the GDC environment and retrieve the management API server kubeconfig:

    gdcloud config set core/organization_console_url "${GDC_ZONAL_CONSOLE_URL}"
    gdcloud config set core/project "${GDC_PROJECT}"
    gdcloud config set core/zone "${GDC_ZONE}"
    gdcloud auth login
    
    export KUBECONFIG="${GDC_MANAGEMENT_API_KUBECONFIG}"
    gdcloud clusters get-credentials "${GDC_MANAGEMENT_API_SERVER}" \
    --zone="${GDC_ZONE}"
    
  2. Verify or create the vm-images-bucket object storage bucket in the project namespace, and wait for it to report BucketReady:

    if ! kubectl get bucket.object.gdc.goog "${GDCS_VM_IMAGES_BUCKET}" --namespace="${GDC_PROJECT}" >/dev/null 2>&1; then
      cat << EOF > "${GDCS_IMPLEMENTATION_HOME}/manifests/vm-images-bucket.yaml"
    apiVersion: object.gdc.goog/v1
    kind: Bucket
    metadata:
      name: ${GDCS_VM_IMAGES_BUCKET}
      namespace: ${GDC_PROJECT}
    spec:
      description: Scratch bucket for imported VM images
      storageClass: Standard
    EOF
    
      kubectl apply \
      --filename="${GDCS_IMPLEMENTATION_HOME}/manifests/vm-images-bucket.yaml" \
      --namespace="${GDC_PROJECT}"
    fi
    
    kubectl wait bucket.object.gdc.goog "${GDCS_VM_IMAGES_BUCKET}" \
    --for=condition=BucketReady \
    --namespace="${GDC_PROJECT}" \
    --timeout=300s
    
  3. Retrieve the bucket endpoint, fully qualified bucket name, and user S3 credentials, then upload the baked image to vm-images-bucket:

    export GDCS_VM_IMAGES_BUCKET_ENDPOINT=$(kubectl get bucket.object.gdc.goog "${GDCS_VM_IMAGES_BUCKET}" \
    --namespace="${GDC_PROJECT}" \
    --output=jsonpath='{.status.endpoint}')
    
    export GDCS_VM_IMAGES_BUCKET_FQN=$(kubectl get bucket.object.gdc.goog "${GDCS_VM_IMAGES_BUCKET}" \
    --namespace="${GDC_PROJECT}" \
    --output=jsonpath='{.status.fullyQualifiedName}')
    
    export GDCS_S3_KEY_SECRET=$(kubectl auth can-i --list --namespace=object-storage-access-keys \
      | grep -oE 'object-storage-key-std-user-[a-z0-9]+' | head -n 1)
    
    set +o history
    gdcloud config set storage/s3_endpoint "${GDCS_VM_IMAGES_BUCKET_ENDPOINT}"
    gdcloud config set storage/s3_access_key_id "$(kubectl get secret "${GDCS_S3_KEY_SECRET}" --namespace=object-storage-access-keys --output=jsonpath='{.data.access-key-id}' | base64 --decode)"
    gdcloud config set storage/s3_secret_access_key "$(kubectl get secret "${GDCS_S3_KEY_SECRET}" --namespace=object-storage-access-keys --output=jsonpath='{.data.secret-access-key}' | base64 --decode)"
    set -o history
    
    gdcloud storage cp "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}" "s3://${GDCS_VM_IMAGES_BUCKET_FQN}/$(basename "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}")"
    
  4. Create the VirtualMachineImageImport resource with operatingSystem: ${GDCS_UBUNTU2404_IMAGE_OS} and prepareImage: false to register ${GDCS_UBUNTU2404_IMAGE_NAME} in the project namespace:

    cat << EOF > "${GDCS_IMPLEMENTATION_HOME}/manifests/${GDCS_UBUNTU2404_IMAGE_NAME}-import.yaml"
    apiVersion: virtualmachine.gdc.goog/v1
    kind: VirtualMachineImageImport
    metadata:
      name: ${GDCS_UBUNTU2404_IMAGE_NAME}
      namespace: ${GDC_PROJECT}
    spec:
      imageMetadata:
        minimumDiskSize: ${GDCS_UBUNTU2404_IMAGE_MIN_DISK_SIZE}
        name: ${GDCS_UBUNTU2404_IMAGE_NAME}
        operatingSystem: ${GDCS_UBUNTU2404_IMAGE_OS}
      prepareImage: false
      source:
        objectStorage:
          bucketRef:
            name: ${GDCS_VM_IMAGES_BUCKET}
          objectName: $(basename "${GDCS_UBUNTU2404_BAKED_QCOW2_FILE}")
    EOF
    
    kubectl apply \
    --filename="${GDCS_IMPLEMENTATION_HOME}/manifests/${GDCS_UBUNTU2404_IMAGE_NAME}-import.yaml" \
    --namespace="${GDC_PROJECT}"
    
  5. Wait for the VirtualMachineImageImport to report Ready=True and verify that the custom VirtualMachineImage is registered in the project:

    kubectl wait virtualmachineimageimport.virtualmachine.gdc.goog "${GDCS_UBUNTU2404_IMAGE_NAME}" \
    --for=condition=Ready \
    --namespace="${GDC_PROJECT}" \
    --timeout=3600s
    
    kubectl get virtualmachineimage.virtualmachine.gdc.goog "${GDCS_UBUNTU2404_IMAGE_NAME}" \
    --namespace="${GDC_PROJECT}" \
    --output=jsonpath='{.metadata.name}{" "}{.spec.minimumDiskSize}{"\n"}'
    

    The output is similar to the following:

    ubuntu-2404-custom 20Gi
    

Create a test VM and verify SSH access

  1. Create a test virtual machine instance from the imported Ubuntu 24.04 image with external SSH access enabled:

    gdcloud compute instances create "${GDCS_TEST_VM_NAME}" \
    --boot-disk-size="${GDCS_TEST_VM_BOOT_DISK_SIZE}" \
    --enable-external-access \
    --image="${GDCS_UBUNTU2404_IMAGE_NAME}" \
    --machine-type="${GDCS_TEST_VM_MACHINE_TYPE}" \
    --no-boot-disk-auto-delete=false \
    --project="${GDC_PROJECT}"
    
  2. Create and apply the ProjectNetworkPolicy that admits administrative SSH traffic on TCP port 22:

    cat << EOF > "${GDCS_IMPLEMENTATION_HOME}/manifests/${GDCS_TEST_VM_SSH_PNP_NAME}-pnp.yaml"
    apiVersion: networking.gdc.goog/v1
    kind: ProjectNetworkPolicy
    metadata:
      name: ${GDCS_TEST_VM_SSH_PNP_NAME}
      namespace: ${GDC_PROJECT}
    spec:
      ingress:
        - from:
            - ipBlock:
                cidr: ${GDCS_TEST_VM_ADMIN_CIDR}
          ports:
            - port: 22
              protocol: TCP
      policyType: Ingress
      subject:
        subjectType: UserWorkload
    EOF
    
    kubectl apply \
    --filename="${GDCS_IMPLEMENTATION_HOME}/manifests/${GDCS_TEST_VM_SSH_PNP_NAME}-pnp.yaml" \
    --namespace="${GDC_PROJECT}"
    
  3. Wait for the test VM and its VirtualMachineExternalAccess custom resource to report Ready=True, and retrieve the external ingress IP address:

    kubectl wait virtualmachine.virtualmachine.gdc.goog "${GDCS_TEST_VM_NAME}" \
    --for=condition=Ready \
    --namespace="${GDC_PROJECT}" \
    --timeout=600s
    
    kubectl wait virtualmachineexternalaccess.virtualmachine.gdc.goog "${GDCS_TEST_VM_NAME}" \
    --for=condition=Ready \
    --namespace="${GDC_PROJECT}" \
    --timeout=300s
    
    export GDCS_TEST_VM_INGRESS_IP=$(kubectl get virtualmachineexternalaccess.virtualmachine.gdc.goog "${GDCS_TEST_VM_NAME}" \
    --namespace="${GDC_PROJECT}" \
    --output=jsonpath='{.status.ingressIP}')
    
    echo "GDCS_TEST_VM_INGRESS_IP=${GDCS_TEST_VM_INGRESS_IP}"
    
  4. Connect over SSH using the baked administrative key and verify OS version, expanded root file system, and active services:

    ssh \
    -i "${GDCS_VM_ADMIN_SSH_KEY_FILE}" \
    -o ConnectTimeout=15 \
    -o StrictHostKeyChecking=accept-new \
    "${GDCS_VM_ADMIN_USER}@${GDCS_TEST_VM_INGRESS_IP}" \
    "hostnamectl; df -h /; systemctl is-active chrony ssh"
    

    The output is similar to the following:

    Operating System: Ubuntu 24.04 ...
    ...
    active
    active
    
  5. Delete the test virtual machine instance and temporary ProjectNetworkPolicy:

    gdcloud compute instances delete "${GDCS_TEST_VM_NAME}" \
    --project="${GDC_PROJECT}" \
    --quiet
    
    kubectl delete projectnetworkpolicy.networking.gdc.goog "${GDCS_TEST_VM_SSH_PNP_NAME}" \
    --ignore-not-found=true \
    --namespace="${GDC_PROJECT}"
    

What's next