Skip to content

Instantly share code, notes, and snippets.

@jcpowermac
Last active Jun 4, 2020
Embed
What would you like to do?
windows kubevirt

Windows Image Template

yum install /usr/bin/virt-install virtio-win
virt-install \
  --name 2016 \
  --memory 8192 \
  --vcpus 2 \
  --cpu host \
  --video cirrus \
  --features hyperv_relaxed=on,hyperv_spinlocks=on,hyperv_vapic=on \
  --clock hypervclock_present=yes \
  --controller=scsi,model=virtio-scsi \
  --disk /storage/2016.raw,bus=scsi,discard=unmap \
  --disk /storage/windows.iso,device=cdrom,bus=ide \
  --disk /usr/share/virtio-win/virtio-win.iso,device=cdrom,bus=ide \
  --network network=default \
  --graphics vnc,listen=0.0.0.0 \
  --noautoconsole \
  --os-type=windows \
  --os-variant=win2k16

In Windows

Enable RDP

  • sconfig.cmd
  • cscript C:\Windows\System32\Scregedit.wsf /ar 0

Software

Drivers

Use pnputil /add-driver .inf to install drivers which should be available on the ISO that is attached.

Install OpenSSH Server
Install cloudbase-init
$address = "https://www.cloudbase.it/downloads/CloudbaseInitSetup_x64.msi"
$filename = "cloudinit.msi"
(new-object system.net).DownloadFile($address, $filename)

NOTE: DO NOT REBOOT

Configure cloudbase-init

Modify C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\cloudbase-init*.conf

  • Add Setting password plugin
  • Add first_logon_behaviour=no
  • Add inject_user_password=true

NOTE: first_logon_behaviour set to no will not require a password change at first logon.

Create Config Drive

qemu-img create -f raw cloudinit.img 1M
mkfs.vfat -n config-2 -I cloudinit.img
mkdir -p /mnt/config-drive
mount -o loop cloudinit.img /mnt/config-drive/

Directory structure

[root@jcallen-node4 config-drive]# tree
.
└── openstack
    └── latest
        ├── meta_data.json
        ├── user_data
        └── vendor_data.json

Copy to already existing local pv

cp cloudinit.img /storage/pv16/disk.img
setfacl -m user:107:rwx /storage/pv16/disk.img

Notes

  • With cloudbase-init virtctl console <vm> is availble with debug information of the cloudbase-init process. Run the command right after starting the virtual machine.
  • I really wish this would work:
oc exec virt-launcher-vm01-kfqxp -i -t -- virsh qemu-agent-command virtualmachine_vm01 '{"execute":"guest-network-get-interfaces"}'                                                                                                                                 
error: argument unsupported: QEMU guest agent is not configured
  • IP Addresses:
ssh admin$(oc get pod -l kubevirt.io/domain=vm01 --template '{{ range .items }} {{.status.podIP}} {{ end }}')
powershell -Command "& {Get-NetIPAddress | Format-Table}"

#one-liner...
 ssh admin$(oc get pod -l kubevirt.io/domain=vm01 --template '{{ range .items }} {{.status.podIP}} {{ end }}') "powershell -Command \"& {Get-NetIPAddress | Format-Table}\""
[DEFAULT]
username=Admin
groups=Administrators
inject_user_password=true
first_logon_behaviour=no
config_drive_raw_hhd=true
config_drive_cdrom=true
config_drive_vfat=true
bsdtar_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe
mtools_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\
verbose=true
debug=true
logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
logfile=cloudbase-init-unattend.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=COM1,115200,N,8
mtu_use_dhcp_config=true
ntp_use_dhcp_config=true
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService,cloudbaseinit.metadata.services.httpservice.HttpService,cloudbaseinit.metadata.services.ec2service.EC2Service,cloudbaseinit.metadata.services.maasservice.MaaSHttpService
plugins=cloudbaseinit.plugins.common.mtu.MTUPlugin,cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin,cloudbaseinit.plugins.windows.setuserpassword.SetUserPasswordPlugin
allow_reboot=false
stop_service_on_exit=false
check_latest_version=false
[DEFAULT]
username=Admin
groups=Administrators
inject_user_password=true
first_logon_behaviour=no
config_drive_raw_hhd=true
config_drive_cdrom=true
config_drive_vfat=true
bsdtar_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe
mtools_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\
verbose=true
debug=true
logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\
logfile=cloudbase-init.log
default_log_levels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN
logging_serial_port_settings=COM1,115200,N,8
mtu_use_dhcp_config=true
ntp_use_dhcp_config=true
local_scripts_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\
{"admin_pass": "ap@ssw0rdthatwillwork"}
---
apiVersion: kubevirt.io/v1alpha2 [11/1875]
kind: VirtualMachine
metadata:
labels:
kubevirt-vm: vm01
name: vm01
namespace: virtualmachine
spec:
running: false
template:
metadata:
creationTimestamp: null
labels:
kubevirt-vm: vm01
spec:
domain:
clock:
timer:
hpet:
present: false
hyperv: {}
pit:
tickPolicy: delay
rtc:
tickPolicy: catchup
cpu:
cores: 2
devices:
disks:
- bootOrder: 1
disk:
bus: scsi
name: disk0
volumeName: pvc01
- bootOrder: 2
disk:
bus: scsi
name: disk1
volumeName: pvc16
interfaces:
- bridge: {}
name: default
- bridge: {}
macAddress: 20:37:cf:e0:ad:f0
name: red
features:
acpi: {}
apic: {}
hyperv:
relaxed: {}
spinlocks:
spinlocks: 8191
vapic: {}
machine:
type: q35
resources:
overcommitGuestOverhead: true
requests:
memory: 8Gi
networks:
- name: default
pod: {}
- hostBridge:
bridgeName: red
nodeBridgeName: red
name: red
nodeSelector:
kubernetes.io/hostname: node4
terminationGracePeriodSeconds: 0
volumes:
- name: pvc01
persistentVolumeClaim:
claimName: pvc01
- name: pvc16
persistentVolumeClaim:
claimName: pvc16
@Icedroid
Copy link

Icedroid commented Jun 4, 2020

where is /storage/2016.raw /storage/windows.iso, where cloud I download them? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment