### Build Ubuntu VM Rootfs from Container Image Source: https://github.com/smartxworks/virtink/blob/main/docs/disks_and_volumes.md This Dockerfile example demonstrates how to build a Ubuntu VM root filesystem from an official Ubuntu container image. It installs necessary packages like systemd, cloud-init, and openssh-server, then copies the rootfs into the Virtink base image. ```dockerfile FROM ubuntu:jammy AS rootfs RUN apt-get update -y && \ apt-get install -y --no-install-recommends systemd-sysv udev lsb-release cloud-init sudo openssh-server && \ rm -rf /var/lib/apt/lists/* FROM smartxworks/virtink-container-rootfs-base COPY --from=rootfs / /rootfs RUN ln -sf ../run/systemd/resolve/stub-resolv.conf /rootfs/etc/resolv.conf ``` -------------------------------- ### Build Custom Kernel for Direct Boot Source: https://github.com/smartxworks/virtink/blob/main/docs/direct_kernel_boot.md Dockerfile example for building a custom kernel image. The `vmlinux` file must be copied to the `/vmlinux` path in an image based on `smartxworks/virtink-kernel-base`. ```dockerfile FROM smartxworks/virtink-kernel-base COPY vmlinux /vmlinux ``` -------------------------------- ### Access VM via SSH using kubectl run Source: https://github.com/smartxworks/virtink/blob/main/README.md Connect to a running Virtink VM via SSH. This example uses `kubectl run` to launch an Alpine container, install an SSH client, and then connect to the VM's IP address. ```bash export VM_NAME=ubuntu-container-rootfs export VM_POD_NAME=$(kubectl get vm $VM_NAME -o jsonpath='{.status.vmPodName}') export VM_IP=$(kubectl get pod $VM_POD_NAME -o jsonpath='{.status.podIP}') kubectl run ssh-$VM_NAME --rm --image=alpine --restart=Never -it -- /bin/sh -c "apk add openssh-client && ssh ubuntu@$VM_IP" ``` -------------------------------- ### Create a Virtual Machine with Container Rootfs Source: https://github.com/smartxworks/virtink/blob/main/README.md Define and apply a Kubernetes VirtualMachine manifest. This example creates an Ubuntu VM using a container rootfs and cloud-init for configuration. ```yaml apiVersion: virt.virtink.smartx.com/v1alpha1 kind: VirtualMachine metadata: name: ubuntu-container-rootfs spec: instance: memory: size: 1Gi kernel: image: smartxworks/virtink-kernel-5.15.12 cmdline: "console=ttyS0 root=/dev/vda rw" disks: - name: ubuntu - name: cloud-init interfaces: - name: pod volumes: - name: ubuntu containerRootfs: image: smartxworks/virtink-container-rootfs-ubuntu size: 4Gi - name: cloud-init cloudInit: userData: |- #cloud-config password: password chpasswd: { expire: False } ssh_pwauth: True networks: - name: pod pod: {} ``` -------------------------------- ### Install Virtink Components Source: https://github.com/smartxworks/virtink/blob/main/README.md Apply the Virtink YAML manifest to install all necessary components into your Kubernetes cluster. This command deploys the controller, daemon, and other required resources. ```bash kubectl apply -f https://github.com/smartxworks/virtink/releases/download/v0.13.0/virtink.yaml ``` -------------------------------- ### Install Cert-Manager Source: https://github.com/smartxworks/virtink/blob/main/README.md Install cert-manager, a requirement for Virtink, using its official YAML manifest. Ensure you are using a compatible version. ```bash kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cert-manager.yaml ``` -------------------------------- ### Reference DataVolume for VM Disk Source: https://github.com/smartxworks/virtink/blob/main/docs/disks_and_volumes.md This YAML manifest demonstrates how to use a DataVolume to provide a disk for a Virtink VirtualMachine. This automates the creation of a PVC and the import of data into it. The VM will not start until the DataVolume import is complete. ```yaml apiVersion: virt.virtink.smartx.com/v1alpha1 kind: VirtualMachine spec: instance: disks: - name: ubuntu volumes: - name: ubuntu dataVolume: volumeName: ubuntu ``` -------------------------------- ### Attach PersistentVolumeClaim to VM Disk Source: https://github.com/smartxworks/virtink/blob/main/docs/disks_and_volumes.md This YAML manifest shows how to attach a PersistentVolumeClaim (PVC) as a disk to a Virtink VirtualMachine. Use this when the VM's disk data needs to persist after the VM terminates. The PVC must be named 'ubuntu' in this example. ```yaml apiVersion: virt.virtink.smartx.com/v1alpha1 kind: VirtualMachine spec: instance: disks: - name: ubuntu volumes: - name: ubuntu persistentVolumeClaim: claimName: ubuntu ``` -------------------------------- ### Embed Cloud-Init User Data in VM Spec Source: https://github.com/smartxworks/virtink/blob/main/docs/disks_and_volumes.md Attach cloud-init data-sources to a VM by embedding user-data directly in the VM specification. This allows the VM's cloud-init setup to pick up the disk as a user-data source. Supports `userData`, `userDataBase64`, and `userDataSecretName`. ```yaml apiVersion: virt.virtink.smartx.com/v1alpha1 kind: VirtualMachine spec: instance: disks: - name: ubuntu - name: cloud-init volumes: - name: ubuntu containerDisk: image: smartxworks/virtink-container-disk-ubuntu - name: cloud-init cloudInit: userData: |- #cloud-config password: password chpasswd: { expire: False } ssh_pwauth: True ``` -------------------------------- ### Configure SR-IOV Device Plugin Source: https://github.com/smartxworks/virtink/blob/main/docs/interfaces_and_networks.md Create a ConfigMap for the SR-IOV Device Plugin to recognize and allocate the prepared VF. Ensure VENDOR_ID and DEVICE_ID variables are set correctly. ```bash echo $VENDOR_ID # make sure it's the vendor ID of your VF echo $DEVICE_ID # make sure it's the device ID of your VF cat < /sys/bus/pci/drivers/$DRIVER/unbind export VENDOR_ID=$(lspci -s $VF_ADDR -Dn | awk '{split($3,a,":"); print a[1]}') export DEVICE_ID=$(lspci -s $VF_ADDR -Dn | awk '{split($3,a,":"); print a[2]}') echo $VENDOR_ID $DEVICE_ID > /sys/bus/pci/drivers/vfio-pci/new_id ``` -------------------------------- ### Create SR-IOV NetworkAttachmentDefinition Source: https://github.com/smartxworks/virtink/blob/main/docs/interfaces_and_networks.md Define a Multus NetworkAttachmentDefinition to make the SR-IOV VF available as a network for Virtink VMs. The resourceName annotation must match the device plugin's resourceList. ```bash cat <