Adding Image Sources

An image source records where a virtual machine image is stored — a container registry, an HTTP server or an S3 bucket — and which projects may use it. It is a platform resource (VirtualMachineImageTemplate), shared by all clusters. Virtual machines can import their system disk straight from an image source, or an administrator can import it once into a cluster as an image instance, from which virtual machines are cloned.

The platform supports X86_64 and ARM64 (Alpha) images.

Procedure

  1. Access Administrator.

  2. In the left navigation bar, click Virtualization > Images > Image Source.

  3. Click Add Image Source.

  4. Refer to the instructions below to configure the relevant parameters.

    ParameterDescription
    Name / Display NameThe name of the image source and an optional display name.
    Operating SystemCentOS, Ubuntu, RedHat, Debian, TLinux, Other Linux or Windows (Alpha).
    Source
    • Registry: a virtual machine image stored in a container image registry (a container disk).
    • HTTP: a virtual machine image file on a file server, over HTTP or HTTPS.
    • Object storage (S3): a virtual machine image in S3-compatible object storage. An S3 image that needs no authentication can be added with HTTP instead.
    CPU ArchThe CPU architecture of the image. For a registry source, both architectures can be selected; for the other sources, one.
    Image URLA KVM virtual machine image in qcow2 or raw format.
    • Registry: repository_address:image_version, for example registry.example.com/library/ubuntu:latest.
    • HTTP: the URL of the image file, starting with http:// or https://, for example http://192.168.0.1/vm_image/centos_7.8.qcow2.
    • S3: the address of the object, for example https://endpoint/bucket/centos.qcow2.
    AuthorizationTurn on if the source requires authentication, then select an image credential or click Add Credential; only Username/Password credentials are supported. Authorization cannot be turned off for an S3 source.
    Allocated Projects
    • All Projects: every project may use the image.
    • Specific projects: only the selected projects.
    • None: no project for now; assign projects later by updating the image source.
  5. Click Add.

Note:

  • An image server whose HTTPS certificate is self-signed or issued by a private CA cannot be used directly from an image source: CDI needs the CA certificate, which only an image instance carries. Add an image instance from the image source with its CA Certificate, and create virtual machines from the image instance. When you choose such an image source in the Create Virtual Machine form, the form reminds you of this.
  • An image source that requires authentication, or an S3 image source, can be imported as an image instance only in a namespace, where the credential Secret lives; see Image Instances in a Namespace.

Default specification

An image source can declare the instance type and preference virtual machines created from the image should use, with the four instancetype.kubevirt.io/default-* labels. An image source is shared by all clusters while instance types and preferences belong to a cluster, so the console does not offer these settings: declare them in YAML, and use only names that exist on every cluster where the image is used. Editing an image source in the console keeps these labels.

The image sources supplied with the platform declare the instance type u1.small, and on X86_64 the preference rhel.7 (CentOS 7) or ubuntu (Ubuntu 20.04).

The labels are used as follows:

  • An image instance added from the image source carries them over.
  • When you create a virtual machine from the image source, the instance type and preference are preselected in the Model area. A name that does not exist on the cluster is not preselected, and the form says so.

Using the API

apiVersion: virtualization.alauda.io/v1
kind: VirtualMachineImageTemplate
metadata:
  name: centos-7-9
  labels:
    virtualization.cpaas.io/image-os-type: centos
    virtualization.cpaas.io/image-os-arch: amd64          # amd64 | arm64 | amd64.arm64
    project.cpaas.io/ALL_ALL: "true"                      # allocated to all projects
    # optional default specification
    instancetype.kubevirt.io/default-instancetype: u1.small
    instancetype.kubevirt.io/default-instancetype-kind: VirtualMachineClusterInstancetype
    instancetype.kubevirt.io/default-preference: rhel.7
    instancetype.kubevirt.io/default-preference-kind: VirtualMachineClusterPreference
  annotations:
    cpaas.io/display-name: CentOS 7.9
spec:
  source: http                      # registry | http | s3
  url: https://images.example.com/centos-7.9.qcow2
  # secret:
  #   name: image-credential        # for a source that requires authentication

Apply it on the global cluster:

kubectl apply -f centos-7-9.yaml
kubectl get virtualmachineimagetemplates