Introduction
Two ways to create virtual machines.
Create a Single VM
- Creates only one KVM virtual machine (via KubeVirt VirtualMachine resource), automatically detects international or domestic server
- Uses the cluster CNI address space; a dual-stack cluster detects VM IPv4 and IPv6 separately for port forwarding
- Supports x86_64 and ARM64 architecture servers
IPv6 network mode
KubeVirt never derives a CNI/IPAM subnet from the host's public IPv6 prefix. When IPv6 forwarding is enabled, the installer preserves the SLAAC route on the host uplink; VM IPv6 availability depends on the cluster CNI dual-stack configuration.
Download Script
shell
curl -sSLO https://raw.githubusercontent.com/oneclickvirt/kubevirt/main/scripts/onevm.sh
chmod +x onevm.sh1
2
2
Example
Supported variables:
bash
./onevm.sh <name> <cpu> <memory_gb> <disk_gb> <password> <sshport> <startport> <endport> [system]1
Currently supported systems:
- debian
- ubuntu
Default is debian if not specified.
shell
./onevm.sh vm1 1 1 10 MyPassword 25000 34975 35000 debian1
Example VM details:
| Property | Value |
|---|---|
| VM name | vm1 |
| SSH username | root |
| SSH password | MyPassword |
| CPU cores | 1 |
| Memory | 1024MB |
| Disk size | 10GB |
| SSH port | 25000 |
| Port mapping range | 34975 to 35000 |
| System | debian |
Related Operations
List all virtual machines
shell
kubectl get vmi -n default1
Check VM status
shell
kubectl get vm vm1 -n default1
Start a virtual machine
shell
virtctl start vm1 -n default1
Stop a virtual machine
shell
virtctl stop vm1 -n default1
Access VM serial console
shell
virtctl console vm1 -n default1
Press Ctrl + ] to exit the console.
Delete example
shell
kubectl delete vm vm1 -n default
kubectl delete pvc vm1-pvc -n default1
2
2
Batch Create VMs
- Generates multiple VMs inheriting the same configuration
- Automatically increments VM names (vm1, vm2, ...), SSH ports, and public ports
- VM information is logged to the
vmlogfile - It is recommended to run in a screen session when creating multiple VMs to avoid SSH disconnection
- Supports x86_64 and ARM64 architecture servers
Run
shell
curl -sSLO https://raw.githubusercontent.com/oneclickvirt/kubevirt/main/scripts/create_kubevirt.sh
chmod +x create_kubevirt.sh
./create_kubevirt.sh1
2
3
2
3
Query Batch Creation Info
shell
cat vmlog1
Output format:
VM-name SSH-port root-password CPU-cores memory disk start-port end-port1
One line per VM.
Delete All VMs and Images
shell
kubectl delete vm --all -n default
kubectl delete pvc --all -n default
rm -rf vmlog1
2
3
2
3
Recover After Host Reboot
The k3s service starts automatically on boot. After a reboot:
shell
# Check k3s status
systemctl status k3s
# Check KubeVirt pod status
kubectl get pods -n kubevirt
# Start all stopped VMs
for vm in $(kubectl get vm -n default --no-headers -o custom-columns=':metadata.name'); do
virtctl start "$vm" -n default 2>/dev/null
done1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
