2.3. Using the Alpine disk
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.
Note
This Alpine Cloud Image has cloud-init included. We will need another disk (cloudinitdisk) which configures our environment. We will look into cloud-init in a later section. For now, just use the cloudinitdisk specification from the snippet below.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
Cleanup resources
You have reached the end of this lab. Please stop your running virtual machines to save resources on the cluster.
Stop your running VM with:
virtctl stop lab02-alpine --namespace lab-<username>
Delete your DataVolume which will delete the PVC and free the diskspace:
kubectl delete dv lab02-alpinedisk --namespace lab-<username>