virtink

module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2022 License: Apache-2.0

README

Virtink: Lightweight Virtualization Add-on for Kubernetes

build Go Report Card codecov

Virtink is a Kubernetes add-on for running Cloud Hypervisor virtual machines. By using Cloud Hypervisor as the underlying hypervisor, Virtink enables a lightweight and secure way to run fully virtualized workloads in a canonical Kubernetes cluster.

Compared to KubeVirt, Virtink:

  • does not use libvirt or QEMU. By leveraging Cloud Hypervisor, VMs has lower memory (≈30MB) footprints, higher performance and smaller attack surface.
  • does not require a long-running per-Pod launcher process, which further reduces runtime memory overhead (≈80MB).
  • is an especially good fit for running fully isolated Kubernetes clusters in an existing Kubernetes cluster. See our Cluster API provider and the knest tool for more details.

Virtink consists of 3 components:

  • virt-controller is the cluster-wide controller, responsible for creating Pods to run Cloud Hypervisor VMs.
  • virt-daemon is the per-Node daemon, responsible for further controlling Cloud Hypervisor VMs on Node bases.
  • virt-prerunner is the per-Pod pre-runner, responsible for preparing VM networks and building Cloud Hypervisor VM configuration.

NOTE: Virtink is still a work in progress, its API may change without prior notice.

Installation

Requirements

A few requirements need to be met before you can begin:

  • Kubernetes cluster 1.16 ~ 1.24
  • Kubernetes apiserver must have --allow-privileged=true in order to run Virtink's privileged DaemonSet. It's usually set by default.
Container Runtime Support

Virtink currently supports the following container runtimes:

  • Docker
  • containerd

Other container runtimes, which do not use virtualization features, should work too. However, they are not tested officially.

Hardware Virtualization Support

Hardware with virtualization support is required. You should check if /dev/kvm exists on each Kubernetes nodes.

Install Virtink

Install all Virtink components:

kubectl apply -f https://github.com/smartxworks/virtink/releases/download/v0.8.0/virtink.yaml

Once you have deployed Virtink, you can create your virtual machines.

Getting Started

Create a VM

Apply the following manifest to Kubernetes. Note it uses a container disk and as such doesn’t persist data.

cat <<EOF | kubectl apply -f -
apiVersion: virt.virtink.smartx.com/v1alpha1
kind: VirtualMachine
metadata:
  name: ubuntu-container-disk
spec:
  instance:
    memory:
      size: 1Gi
    disks:
      - name: ubuntu
      - name: cloud-init
    interfaces:
      - name: pod
  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
  networks:
    - name: pod
      pod: {}
EOF

Like starting pods, it will take some time to pull the image and start running the VM. You can wait for the VM become running as follows:

kubectl wait vm ubuntu-container-disk --for jsonpath='{.status.phase}'=Running
Access the VM (via SSH)

The easiest way to access the VM is via a SSH client inside the cluster. You can access the VM created above as follows:

export VM_NAME=ubuntu-container-disk
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 $VM_NAME-ssh --rm --image=alpine --restart=Never -it -- /bin/sh -c "apk add openssh-client && ssh ubuntu@$VM_IP"

Enter password when you are prompted to enter password, which is set by the cloud-init data in the VM manifest.

Manage the VM

Virtink supports various VM power actions. For example, you can ACPI shutdown the VM created above as follows:

export VM_NAME=ubuntu-container-disk
export POWER_ACTION=Shutdown
kubectl patch vm $VM_NAME --subresource=status --type=merge -p "{\"status\":{\"powerAction\":\"$POWER_ACTION\"}}"

You can also PowerOff, Reset, Reboot or Pause a running VM, or Resume a paused one. To start a powered-off VM, you can PowerOn it.

Roadmap

  • VM lifecycle management
  • Container disks
  • Direct kernel boot with container rootfs
  • Pod network
  • Multus CNI networks
  • Persistent volumes
  • CDI data volumes
  • ARM64 support
  • VM live migration
  • SR-IOV NIC passthrough
  • GPU passthrough

License

This project is distributed under the Apache License, Version 2.0.

Directories

Path Synopsis
cmd
virt-controller command
virt-daemon command
virt-prerunner command
pkg
apis/virt/v1alpha1
Package v1alpha1 is the v1alpha1 version of the API.
Package v1alpha1 is the v1alpha1 version of the API.
generated/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
generated/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
generated/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
generated/clientset/versioned/typed/virt/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
generated/clientset/versioned/typed/virt/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL