|
| 1 | +# VirtualMachine Creation Plan |
| 2 | + |
| 3 | +**IMPORTANT**: Always use `runStrategy` instead of the deprecated `running` field when creating VirtualMachines. |
| 4 | + |
| 5 | +Use the `resources_create_or_update` tool with the following YAML: |
| 6 | + |
| 7 | +```yaml |
| 8 | +apiVersion: kubevirt.io/v1 |
| 9 | +kind: VirtualMachine |
| 10 | +metadata: |
| 11 | + name: {{.Name}} |
| 12 | + namespace: {{.Namespace}} |
| 13 | +spec: |
| 14 | + runStrategy: Halted |
| 15 | +{{- if .Instancetype}} |
| 16 | + instancetype: |
| 17 | + name: {{.Instancetype}} |
| 18 | + kind: VirtualMachineClusterInstancetype |
| 19 | +{{- end}} |
| 20 | +{{- if .Preference}} |
| 21 | + preference: |
| 22 | + name: {{.Preference}} |
| 23 | + kind: VirtualMachineClusterPreference |
| 24 | +{{- end}} |
| 25 | +{{- if .UseDataSource}} |
| 26 | + dataVolumeTemplates: |
| 27 | + - metadata: |
| 28 | + name: {{.Name}}-rootdisk |
| 29 | + spec: |
| 30 | + sourceRef: |
| 31 | + kind: DataSource |
| 32 | + name: {{.DataSourceName}} |
| 33 | + namespace: {{.DataSourceNamespace}} |
| 34 | + storage: |
| 35 | + resources: |
| 36 | + requests: |
| 37 | + storage: 30Gi |
| 38 | +{{- end}} |
| 39 | + template: |
| 40 | + spec: |
| 41 | + domain: |
| 42 | + devices: |
| 43 | + disks: |
| 44 | + - name: {{.Name}}-rootdisk |
| 45 | +{{- if not .Instancetype}} |
| 46 | + memory: |
| 47 | + guest: 2Gi |
| 48 | +{{- end}} |
| 49 | + volumes: |
| 50 | + - name: {{.Name}}-rootdisk |
| 51 | +{{- if .UseDataSource}} |
| 52 | + dataVolume: |
| 53 | + name: {{.Name}}-rootdisk |
| 54 | +{{- else}} |
| 55 | + containerDisk: |
| 56 | + image: {{.ContainerDisk}} |
| 57 | +{{- end}} |
| 58 | +``` |
| 59 | + |
| 60 | +## Run Strategy Options |
| 61 | + |
| 62 | +The VM is created with `runStrategy: Halted` (stopped state). You can modify the `runStrategy` field to control the VM's execution: |
| 63 | + |
| 64 | +- **`Halted`** - VM is stopped and will not run |
| 65 | +- **`Always`** - VM should always be running (restarts automatically) |
| 66 | +- **`RerunOnFailure`** - Restart the VM only if it fails |
| 67 | +- **`Manual`** - Manual start/stop control via `virtctl start/stop` |
| 68 | +- **`Once`** - Run the VM once, then stop when it terminates |
| 69 | + |
| 70 | +To start the VM after creation, change `runStrategy: Halted` to `runStrategy: Always` or use the Manual strategy and start it with virtctl. |
| 71 | + |
| 72 | +## Verification |
| 73 | + |
| 74 | +After creating the VirtualMachine, verify it was created successfully: |
| 75 | + |
| 76 | +Use the `resources_get` tool: |
| 77 | +- **apiVersion**: `kubevirt.io/v1` |
| 78 | +- **kind**: `VirtualMachine` |
| 79 | +- **namespace**: `{{.Namespace}}` |
| 80 | +- **name**: `{{.Name}}` |
| 81 | + |
| 82 | +Check the resource details for any warnings or errors in the status conditions. |
| 83 | + |
| 84 | +## Troubleshooting |
| 85 | + |
| 86 | +If the VirtualMachine fails to create or start: |
| 87 | + |
| 88 | +1. **Check the VM resource details and events**: |
| 89 | + - Use `resources_get` tool with apiVersion `kubevirt.io/v1`, kind `VirtualMachine`, namespace `{{.Namespace}}`, name `{{.Name}}` |
| 90 | + - Look for error messages in the status conditions |
| 91 | + |
| 92 | +2. **Verify instance type exists** (if specified): |
| 93 | + - Use `resources_get` tool with apiVersion `instancetype.kubevirt.io/v1beta1`, kind `VirtualMachineClusterInstancetype`, name `{{.Instancetype}}` |
| 94 | + |
| 95 | +3. **Verify preference exists** (if specified): |
| 96 | + - Use `resources_get` tool with apiVersion `instancetype.kubevirt.io/v1beta1`, kind `VirtualMachineClusterPreference`, name `{{.Preference}}` |
| 97 | + |
| 98 | +4. **Check KubeVirt installation**: |
| 99 | + - Use `pods_list` tool with namespace `kubevirt` |
0 commit comments