Creating a VM
Creating a VM Using a Manifest File
- Create a VM as follows:
kubectl create -f - <<EOF apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: testvm spec: runStrategy: Halted template: metadata: labels: kubevirt.io/size: small kubevirt.io/domain: testvm spec: domain: devices: disks: - name: containerdisk disk: bus: virtio - name: cloudinitdisk disk: bus: virtio interfaces: - name: default masquerade: {} resources: requests: memory: 64M networks: - name: default pod: {} volumes: - name: containerdisk containerDisk: image: quay.io/kubevirt/cirros-container-disk-demo - name: cloudinitdisk cloudInitNoCloud: userDataBase64: SGkuXG4= EOF
If the command is executed successfully, the following information is displayed:
virtualmachine.kubevirt.io/testvm created
- (The VM is stopped because runStrategy is set to Halted.) Check the VM status.
kubectl get vms
Example output:NAME AGE STATUS READY testvm 73s Stopped False
Creating a VM with Specific Resources Using virtctl
The create vm subcommand of virtctl allows you to easily create your VirtualMachine resource manifest through the command line. By default, this command checks the instance type, preference setting, and inference function, and provides multiple flags to control the detailed settings of the VM. You can run the following command to view all available configuration items:
virtctl create vm -h
For example, to create a VM named vm-cirros with 4-GiB memory, run the following command:
virtctl create vm --name vm-cirros --memory "4Gi" | kubectl create -f -
For more information about creating a VM, see https://kubevirt.io/user-guide/user_workloads/lifecycle/.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot