2.3. Using the Alpine disk

Create a virtual machine using the provisioned Alpine Cloud Disk Image

In the previous section we have provisioned a custom Alpine cloud disk image. We will now create a VM which uses this disk image.

Task 2.3.1: Attach the disk

Write a new VirtualMachine manifest named lab02-alpine.yaml in the directory labs/lab02.

Block needed to reference the PVC as a disk and the cloudinitdisk:

      volumes:
        - name: alpinedisk
          persistentVolumeClaim:
            claimName: lab02-alpinedisk
        - name: cloudinitdisk
          cloudInitNoCloud:
             userData: |-
                #cloud-config
                password: changeme
                chpasswd: { expire: False }                

You will have to reference the cloudinitdisk as a second disk in spec.template.spec.domain.devices.disks.

Task hint

Your yaml should look like this:

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: lab02-alpine
spec:
  runStrategy: Halted
  template:
    spec:
      domain:
        devices:
          disks:
            - name: alpinedisk
              disk:
                bus: virtio
            - name: cloudinitdisk
              disk:
                bus: virtio
          interfaces:
            - name: default
              masquerade: {}
        resources:
          requests:
            memory: 256M
      networks:
        - name: default
          pod: {}
      volumes:
        - name: alpinedisk
          persistentVolumeClaim:
            claimName: lab02-alpinedisk
        - name: cloudinitdisk
          cloudInitNoCloud:
            userData: |-
              #cloud-config
              password: changeme
              chpasswd: { expire: False }              

Task 2.3.2: Create and start the VM

Create the VM on the Kubernetes cluster:

kubectl apply -f labs/lab02/lab02-alpine.yaml --namespace lab-<username>

Start your VM with:

virtctl start lab02-alpine --namespace lab-<username>

Task 2.3.3: Testing the VM

Open the VM’s console:

virtctl console lab02-alpine --namespace lab-<username>

After some time your VM should be successfully provisioned with the Alpine cloud disk image. You should be able to successfully log in with user alpine and the configured password.

End of lab