3.3. Create an instance type

Create your own instance type and preference

In this section, we will create and use our own instance type.

Task 3.3.1: Create your own instance type

In the previous section we have seen that the Cirros preference requests 256Mi of memory. However, the smallest instance type available requests 512Mi of memory. In order to adapt to this, let’s create our own instance type and assign it to our VirtualMachines.

Create a file vmf_lab03-o1-pico.yaml under labs/lab03 As a starting point you can use the definition of the o1.nano instance type.

Define the following instance type:

  • Request 256Mi of memory
  • Reduce the overcommit percentage from 50% to 25%
  • Name the resource lab03-o1-pico
Task hint

Your instance type should look like this (labels and annotations are optional):

apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
  name: lab03-o1-pico
  annotations:
    instancetype.kubevirt.io/description: |-
      The O Series is based on the U Series, with the only difference
      being that memory is overcommitted.
      
      *O* is the abbreviation for "Overcommitted".      
    instancetype.kubevirt.io/displayName: General Purpose
  labels:
    instancetype.kubevirt.io/class: general.purpose
    instancetype.kubevirt.io/cpu: "1"
    instancetype.kubevirt.io/icon-pf: pficon-server-group
    instancetype.kubevirt.io/memory: 256Mi
    instancetype.kubevirt.io/vendor: kubevirt-basics-training
    instancetype.kubevirt.io/version: "1"
spec:
  cpu:
    guest: 1
  memory:
    guest: 256Mi
    overcommitPercent: 25

Create your resource with:

kubectl apply -f labs/lab03/vmf_lab03-o1-pico.yaml --namespace lab-<username>

And verify whether the creation was successful:

kubectl get vmf lab03-o1-pico --namespace lab-<username>

Task 3.3.2: Create your own instance type with virtctl

The virtctl tool is also capable of creating instance types. You can define and create a similar instance type u1.pico with:

virtctl create instancetype --namespaced --cpu 1 --memory 256Mi --name lab03-u1-pico --namespace lab-<username> | kubectl create --namespace lab-<username> -f -

Show the created instance type with:

kubectl get vmf lab03-u1-pico -o yaml --namespace lab-<username>

The output will be similar to this one:

apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
  creationTimestamp: "2024-09-25T09:25:35Z"
  generation: 1
  name: lab03-u1-pico
  namespace: lab-<username>
  resourceVersion: "55713159"
  uid: 14d414b7-b1f8-4b0d-af48-fb84340545c9
spec:
  cpu:
    guest: 1
  memory:
    guest: 256Mi