1 - Detailed Explanation for Configuration File for Custom VMs
To set up a virtual machine you need to create a configuration file. The configuration file contains information, such as name of the VM, used resources (e.g. RAM) and states (e.g. running, halted).
Heed the comments (#) in the file below.
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
labels:
kubevirt.io/vm: example-vm-cirros
name: example-vm
namespace: {{ values.vmValues.namespace | object.default "kubevirt" }}
spec:
runStrategy: Always
template:
metadata:
labels:
kubevirt.io/vm: example-vm-cirros
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: containerdisk
- disk:
bus: virtio
name: cloudinitdisk
machine:
type: ""
resources:
requests:
memory: 64M
terminationGracePeriodSeconds: 0
volumes:
- name: containerdisk
containerDisk:
image: {{ package.includes.containers.example.registry }}/{{ package.includes.containers.example.image }}:{{ package.includes.containers.example.tag }}
imagePullSecret: kubeops-vm
imagePullPolicy: Always
- cloudInitNoCloud:
userDataBase64: IyEvYmluL3NoCgplY2hvICdwcmludGVkIGZyb20gY2xvdWQtaW5pdCB1c2VyZGF0YScK
name: cloudinitdisk
| YAML | Value | Description |
|---|---|---|
| metadata.labels | kubevirt.io/vm: example-vm-cirros | Labels of the virtual machine. Used to identifiy a specific VM. |
| metadata.name | example-vm | The display name of the VM. |
2 - Commandline Operations
Learn the most common command-line operations for managing KubeOps virtual machines - including creating a VM with a YAML configuration file, starting or stopping the VM by patching its runStrategy, viewing the VM or instance status with kubectl describe, restarting the VM (which deletes the instance and causes data loss), and deleting the VM either in a cascading manner (removing the VM and its instance) or by leaving orphaned instances.
Create a new virtual machine
The command kubectl with the paramater create uses the VM configuration file vm-config.yaml. For more detailed explaination on VM configuration files, see [Detailed Explanation for Configuration File for Custom VMs](Detailed Explanation for Configuration File for Custom VMs).
kubectl create -f vm-config.yaml
Start the virtual machine
Start the virtual machine VMNAME. Replace VMNAME with the name of your virtual machine,
kubectl patch virtualmachine VMNAME --type merge -p \
'{"spec":{"runStrategy":"Always"}}'
Status of a virtual machine
Print the status of the virtual machine VMNAME. Replace VMNAME with the name of your virtual machine,
kubectl describe virtualmachine VMNAME
Status of a virtual machine instance
kubectl describe virtualmachineinstance VMNAME
Stop the virtual machine instance
kubectl patch virtualmachine VMNAME--type merge -p \
'{"spec":{"runStrategy":"Halted"}}'
Restart the virtual machine
{{ hazard_notice }} Restarting the virtual machine will delete the virtual machine instance. This action cannot be undone. {{ /hazard_notice }}
kubectl delete virtualmachineinstance vm
Cascade delete (implicit)
Kubectl first deletes the virtual machine, followed by deleting the corresponding virtual machine instance.
Delete the virtual machine VMNAME. Replace VMNAME with the name of your virtual machine,
{{ hazard_notice }} This action cannot be undone. {{ /hazard_notice }}
kubectl delete virtualmachine VMNAME
Cascade delete (explicit)
Kubectl first deletes the virtual machine, followed by deleting the corresponding virtual machine instance.
Delete the virtual machine VMNAME. Replace VMNAME with the name of your virtual machine,
{{ hazard_notice }} This action cannot be undone. {{ /hazard_notice }}
kubectl delete virtualmachine VMNAME --cascade=true
Delete orphans
The running virtual machine is only detached, but not deleted.
Delete orphans of the virtual machine VMNAME. Replace VMNAME with the name of your virtual machine,
kubectl delete virtualmachine VMNAME --cascade=false