Image Instances in a Namespace

Besides the shared image instances an administrator adds to kube-public (see Adding Image Instances), each namespace can hold image instances of its own. A project groups namespaces across clusters; an image instance always lives in one namespace of one cluster — the namespace you are working in under Container Platform — and only virtual machines of that namespace can use it.

Use a namespace image instance when the image should not be shared with every namespace, or when importing it needs a credential: an image on S3, or a registry or HTTP server that requires authentication. kube-public holds no Secret, so such images can only be added in a namespace.

View image instances

  1. Access Container Platform and select the project, cluster and namespace.
  2. In the left navigation bar, click Virtualization > Images > Image Instance.

The list shows:

  • the image instances of the namespace, in any status, with their actions (Update Display Name, Update Default Specification, Re-import, Delete, and Create Virtual Machine) — see Managing Image Instances;
  • the Available image instances of kube-public, marked kube-public. They are read-only here: their only action is Create Virtual Machine.

Add an image instance to the namespace

Add Image Instance requires the permission to create DataSource and DataVolume objects in the namespace. The form is the same as on the administrator page (see Adding Image Instances), with these differences:

  • Every object — the DataSource, the CA certificate ConfigMap and the import DataVolume — is created in the namespace.
  • Image Source lists the image sources assigned to the project. Those that require a credential, and S3 image sources, can be selected too; a Credential must then be chosen.
  • Network offers Registry, HTTP and Object storage (S3). An S3 address takes the form https://endpoint/bucket/object (or http://), and needs a Credential; it can also carry a CA Certificate.
  • Disk and Volume Snapshot list only the disks and volume snapshots of this namespace and of kube-public.

Credential

Credential lists the Secrets of the namespace that carry both keys accessKeyId and secretKey — the format CDI reads for registry, HTTP basic and S3 authentication. The Secret is referenced from the import DataVolume as secretRef; the console does not create or copy Secrets. Create it before adding the image instance:

kubectl create secret generic s3-images -n demo \
  --from-literal=accessKeyId=<access key> \
  --from-literal=secretKey=<secret key>

The import DataVolume of an S3 image instance in the namespace demo:

apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
  name: rocky-9-img-k3x7q
  namespace: demo
spec:
  source:
    s3:
      url: http://rook-ceph-rgw-ceph-object.rook-ceph.svc:7480/images/rocky-9.qcow2
      secretRef: s3-images
      # certConfigMap: rocky-9-img-ca   # an endpoint with a private CA
  storage:
    storageClassName: sc-ceph-cluster-block
    volumeMode: Block
    accessModes:
      - ReadWriteMany
    resources:
      requests:
        storage: 30Gi

Its DataSource is the same as in Adding Image Instances, in the namespace demo and with virtualization.cpaas.io/source-type: address.

For a registry address, a credential is used only by the Pod pull method: once a Credential is chosen, Pull Method is set to Pod and Node is unavailable. With Node, the node's container runtime pulls the image with the node's own access to the registry; CDI passes the Secret to the importer container only, so the node would not use it.

Create a virtual machine from an image instance

Click Create Virtual Machine on a row — of the namespace or of kube-public. The Create Virtual Machine form of the namespace opens with Provision Method > Image Instance, the architecture and the image instance already selected, and the image instance's default instance type and preference preselected.

When you create a virtual machine or a virtual machine pool, or reinstall the operating system, the Image Instance picker lists the image instances of kube-public and of the virtual machine's namespace; those of the namespace are marked with the namespace name. Image instances of other namespaces are not offered. The system disk clones the image instance from the namespace it lives in:

spec:
  dataVolumeTemplates:
    - metadata:
        name: web-01-rootfs
      spec:
        sourceRef:
          kind: DataSource
          name: rocky-9
          namespace: demo        # kube-public for a shared image instance
        storage:
          storageClassName: sc-ceph-cluster-block
          volumeMode: Block
          accessModes:
            - ReadWriteMany
          resources:
            requests:
              storage: 30Gi