Prerequisites#

Creating a VM that runs debian#

In this guide, you’ll learn how to deploy a simple VM that runs debian.

Installation#

  1. Create debian-vm.yml:

    ---
    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
      name: debian-vm
      namespace: vms
    spec:
      runStrategy: Always
      dataVolumeTemplates:
        - metadata:
            name: debian-vm-rootdisk
          spec:
            storage:
              storageClassName: longhorn
              accessModes:
                - ReadWriteOnce
              resources:
                requests:
                  storage: 8Gi
            source:
              registry:
                url: "docker://quay.io/containerdisks/debian:13"
      template:
        metadata:
          labels:
            kubevirt.io/size: small
            kubevirt.io/domain: debian-vm
        spec:
          domain:
            devices:
              disks:
                - name: rootdisk
                  disk:
                    bus: virtio
                - name: cloudinitdisk
                  disk:
                    bus: virtio
              interfaces:
                - name: default
                  masquerade: {}
            resources:
              requests:
                memory: 1Gi
                cpu: "1"
          networks:
            - name: default
              pod: {}
          volumes:
            - name: rootdisk
              dataVolume:
                name: debian-vm-rootdisk
            - name: cloudinitdisk
              cloudInitNoCloud:
                userData: |
                  #cloud-config
                  password: debian
                  chpasswd: { expire: False }
                  ssh_pwauth: False
                  ssh_authorized_keys:
                    - <your ssh.pub key>
                  runcmd:
                    - systemctl enable --now ssh
                networkData: |
                  version: 2
                  ethernets:
                    enp1s0:
                      dhcp4: true
                      addresses: [ fd10:0:2::2/120 ]
                      routes:
                        - to: ::/0
                          via: fd10:0:2::1
  2. Expose ssh port using MetalLB svc:

    apiVersion: v1
    kind: Service
    metadata:
      name: debian-vm-service
      namespace: vms
    spec:
      selector:
        kubevirt.io/domain: debian-vm
      ports:
      - name: ssh
        port: 22
        targetPort: 22
      type: LoadBalancer
  3. You should be able to ssh into this vm, once created, using the LoadBalancer IP.

    kubectl -n vms get svc debian-vm-service
  4. You can learn how to create custom container disk images to run other distros here containerdisk