#VM instructions for virt-todolist vm ## virt-builder ``` virt-builder fedora-39 --size 8G --format qcow2 --update --firstboot-command 'useradd -m -p dog8code test ; chage -d 0 test' ``` * note user-add did not work correctly, cloud-init would be a better choice for the above ## virt-install w/ cloud-init ``` virt-install --name todolist-mariadb-1 \ --memory memory=3072 --cpu host --vcpus 2 --graphics none \ --os-variant fedora39 --import \ --disk /var/lib/libvirt/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2,format=qcow2,bus=virtio \ --disk size=8 \ --network type=network,source=default,model=virtio \ --cloud-init user-data=/var/lib/libvirt/boot/cloud-init/todolist-data ``` ### debug cloud-init ``` # login sudo cloud-init schema --system ``` * https://cloudinit.readthedocs.io/en/latest/reference/examples.html ## packages ``` dnf install golang, git, mariadb, mariadb-server, net-tools, python-requests ``` ## mariadb script ``` sudo dnf install mariadb-server -y sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql -uroot -e "CREATE DATABASE todolist; USE todolist; CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" sudo mysql -uroot -e "grant all privileges on todolist.* to test@'localhost' identified by 'test'; FLUSH PRIVILEGES; " ``` ## turn off the firewall :) ``` systemctl stop firewalld ``` ## todolist ``` git clone https://github.com/weshayutin/todolist-mariadb-go.git ``` ``` See README.MD or go mod tidy go run todolist.go ``` ## test cd /home/test/todolist-mariadb-go/test/ python test.py ## browse open browser to http://$ip:8000 ## pic ![Screenshot from 2024-02-15 13-14-58](https://hackmd.io/_uploads/ryhRexnia.png) # Cirros https://gist.github.com/smurugap/a6c862a76c99331a7f929a14aaa30551 https://github.com/kubevirt/kubevirt/blob/main/examples/vm-cirros.yaml ## cloud-init in vm manifest ``` volumes: - dataVolume: name: fedora-determined-kingfisher name: rootdisk - cloudInitConfigDrive: userData: |- #cloud-config users: - name: fedora password: ry8p-hokq-hy8t chpasswd: { expire: False } - name: test password: dog8code chpasswd: { expire: False } packages: - mariadb-server - unzip runcmd: - systemctl stop firewalld - systemctl disable firewalld - systemctl start mariadb - systemctl enable mariadb - mysql -uroot -e "CREATE DATABASE todolist; USE todolist; CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" - mysql -uroot -e "grant all privileges on todolist.* to test@'localhost' identified by 'test'; FLUSH PRIVILEGES;" - pushd /home/test/ - wget https://github.com/weshayutin/todolist-mariadb-go/releases/download/testing1/todolist-linux-amd64.zip - unzip todolist-linux-amd64.zip - cp systemd/todolist-mariadb.service /etc/systemd/user - popd - sudo systemctl --user daemon-reload - sudo systemctl --user start todolist-mariadb.service - sudo systemctl --user enable todolist-mariadb.service - systemctl disable cloud-init name: cloudinitdisk ``` ## upload small fedora to quay https://docs.openshift.com/container-platform/4.13/virt/virtual_machines/virtual_disks/virt-using-container-disks-with-vms.html ``` apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: fedora-xeric-grasshopper namespace: openshift-virtualization-os-images spec: dataVolumeTemplates: - metadata: name: fedora-xeric-grasshopper-volume spec: sourceRef: kind: DataSource name: tinyfedora namespace: openshift-virtualization-os-images storage: resources: requests: storage: '33285996544' storageClassName: gp3-csi instancetype: name: cx1.large preference: name: fedora running: true template: spec: domain: devices: disks: - disk: bus: virtio name: fedora-xeric-grasshopper-disk - disk: bus: virtio name: cloudinitdisk volumes: - dataVolume: name: fedora-xeric-grasshopper-volume name: fedora-xeric-grasshopper-disk - cloudInitConfigDrive: userData: |- #cloud-config users: - name: fedora password: dog8code chpasswd: { expire: False } - name: test password: dog8code chpasswd: { expire: False } packages: - mariadb-server - unzip runcmd: - systemctl stop firewalld - systemctl disable firewalld - systemctl start mariadb - systemctl enable mariadb - mysql -uroot -e "CREATE DATABASE todolist; USE todolist; CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';" - mysql -uroot -e "grant all privileges on todolist.* to test@'localhost' identified by 'test'; FLUSH PRIVILEGES;" - pushd /home/test/ - wget https://github.com/weshayutin/todolist-mariadb-go/releases/download/testing1/todolist-linux-amd64.zip - unzip todolist-linux-amd64.zip - cp systemd/todolist-mariadb.service /etc/systemd/user - popd - sudo systemctl --user daemon-reload - sudo systemctl --user start todolist-mariadb.service - sudo systemctl --user enable todolist-mariadb.service - systemctl disable cloud-init ``` ## openshift-virt template has a different yaml format ``` name: rootdisk - cloudInitConfigDrive: userData: |- #cloud-config user: fedora password: dog8code chpasswd: { expire: False } name: cloudinitdisk ``` ## WORKING COPY https://github.com/openshift/oadp-operator/pull/1363 ## OpenShift-Virt software emulation https://developers.redhat.com/blog/2020/09/17/how-to-switch-red-hat-openshift-virtualization-from-hardware-virtualization-to-software-emulation#step_3__start_the_virtual_machine_using_software_emulation