Skip to content

Instantly share code, notes, and snippets.

@awels
Last active May 22, 2018 15:41
Show Gist options
  • Select an option

  • Save awels/fd7a46bc39840988b56b0a5708508fc9 to your computer and use it in GitHub Desktop.

Select an option

Save awels/fd7a46bc39840988b56b0a5708508fc9 to your computer and use it in GitHub Desktop.

Getting started with storage

This document assumes you have a working development environment.

************************** THIS ONLY WORKS ON A SINGLE NODE ENVIRONMENT ****************************

Install hostPath storage class provisioner

Brazenly stolen from here as its more dynamic and flexible than my original solution.

$ ./cluster/kubectl.sh apply -f https://gist.githubusercontent.com/awels/adacce22f515724bdc925c878cd67fc9/raw/5375494d62d2c6b9bfca317a1e6c45304d9cbfbb/hostpath-provisioner.yaml

Install CDI controller.

Grab the manifests for creating the controller.

$ wget https://raw.githubusercontent.com/kubevirt/containerized-data-importer/master/manifests/example/golden-pvc.yaml https://raw.githubusercontent.com/kubevirt/containerized-data-importer/master/manifests/controller/cdi-controller-deployment.yaml

Execute starting the CDI controller. We will start it in the default name space as this is a development environment.

$ ./cluster/kubectl.sh create -f cdi-controller-deployment.yaml
serviceaccount "cdi-sa" created
clusterrole "cdi" created
clusterrolebinding "cdi-sa" created
deployment "cdi-deployment" created

Verify the cdi deployment pod is running

$ ./cluster/kubectl.sh get pods

Download and install an actual image

In this example we are downloading a Centos 7 image from the internet in qcow2 format, we can do many different source images, this is just to demonstrate the process.

Edit the golden-pvc.yaml to look like this:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: "golden-pvc"
  labels:
    app: containerized-data-importer
  annotations:
    kubevirt.io/storage.import.endpoint: "https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"   # Required.  Format: (http||s3)://www.myUrl.com/path/of/data
    kubevirt.io/storage.import.secretName: "" # Optional.  The name of the secret containing credentials for the data source
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

Then create the import by running:

$ ./cluster/kubectl.sh create -f golden-pvc.yaml 
persistentvolumeclaim "golden-pvc" created

You can verify your pods are running:

$ ./cluster/kubectl.sh get pods
NAME                             READY     STATUS    RESTARTS   AGE
cdi-deployment-df78b7cc4-m4cnb   1/1       Running   0          45s
importer-golden-pvc4hlwr         1/1       Running   0          14s

To monitor the cdi controller: (Note that your hash after cdi-deployment-, will be different from this example)

$ ./cluster/kubectl.sh logs cdi-deployment-df78b7cc4-m4cnb
I0521 20:37:00.772286       5 controller.go:42] init: complete: CDI controller will create the "docker.io/kubevirt/cdi-importer:0.4.0-alpha.0" version of the importer
W0521 20:37:00.773915       5 client_config.go:529] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I0521 20:37:00.777765       5 controller.go:72] main: created CDI Controller
I0521 20:37:00.777840       5 controller.go:51] Starting CDI controller loop
I0521 20:37:00.878363       5 controller.go:59] Controller cache has synced
I0521 20:37:00.878444       5 controller.go:87] processNextItem: next pvc to process: default/disk-alpine
I0521 20:37:00.878452       5 controller.go:94] processNextItem: annotation "kubevirt.io/storage.import.endpoint" not found, skipping pvc
I0521 20:37:00.878462       5 controller.go:87] processNextItem: next pvc to process: default/disk-custom
I0521 20:37:00.878472       5 controller.go:94] processNextItem: annotation "kubevirt.io/storage.import.endpoint" not found, skipping pvc
I0521 20:37:27.392298       5 controller.go:87] processNextItem: next pvc to process: default/golden-pvc
I0521 20:37:27.392316       5 util.go:62] getEndpointSecret: secret name is missing from annotation "kubevirt.io/storage.import.secretName" in pvc "default/golden-pvc"
I0521 20:37:27.392321       5 controller.go:123] processItem: no secret will be supplied to endpoint "https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
I0521 20:37:27.448761       5 util.go:118] importer pod "default/importer-golden-pvc4hlwr" (image: "docker.io/kubevirt/cdi-importer:0.4.0-alpha.0") created
I0521 20:37:27.448782       5 util.go:80] setAnnoImportPod: adding annotation "kubevirt.io/storage.import.importPodName: importer-golden-pvc4hlwr" to pvc "default/golden-pvc"

To monitor the importer pod: (Note that your hash after importer-golden-, will be different from this example), the process might take a while

$ ./cluster/kubectl.sh logs importer-golden-pvc4hlwr
I0522 15:25:47.146231       5 importer.go:35] main: Starting importer
I0522 15:25:47.146755       5 importer.go:50] main: importing file "cirros-0.4.0-x86_64-disk.img"
W0522 15:25:47.146765       5 dataStream.go:42] NewDataStream: IMPORTER_ACCESS_KEY_ID and/or IMPORTER_SECRET_KEY env variables are empty
I0522 15:25:47.147078       5 dataStream.go:97] Using HTTP GET to fetch data.
I0522 15:25:47.655729       5 importer.go:58] Beginning import from "/0.4.0/cirros-0.4.0-x86_64-disk.img"
I0522 15:25:47.655762       5 decompress.go:26] UnpackData: checking compressed and/or archive for file "cirros-0.4.0-x86_64-disk.img"
I0522 15:25:47.655770       5 decompress.go:45] DecompressData: checking if "cirros-0.4.0-x86_64-disk.img" is compressed
I0522 15:25:47.655777       5 decompress.go:70] DearchiveData: checking if "cirros-0.4.0-x86_64-disk.img" is an archive file
I0522 15:25:47.742409       5 util.go:44] StreamDataToFile: begin import...
I0522 15:25:48.849732       5 importer.go:88] main: converting qcow2 image to raw
I0522 15:25:48.905372       5 importer.go:98] main: Import complete, exiting

Start VM from image

Lets create a VM and connect to it using VNC. Put the following yaml in cirrus-pvc.yaml

apiVersion: kubevirt.io/v1alpha1
kind: VirtualMachine
metadata:
  creationTimestamp: null
  name: vm-pvc-cirrus
spec:
  domain:
    devices:
      disks:
      - disk:
          bus: virtio
        name: pvcdisk
        volumeName: pvcvolume
    machine:
      type: ""
    resources:
      requests:
        memory: 64M
  terminationGracePeriodSeconds: 0
  volumes:
  - name: pvcvolume
    persistentVolumeClaim:
      claimName: golden-pvc
status: {}

Some details to note, we are using the PVC we just created as the source for a virtio disk, and we are giving the new VM 1 gigabyte of memory. We can probably use less if needed.

Now create the VM:

$ ./cluster/kubectl.sh create -f cirrus-pvc.yaml
virtualmachine "vm-pvc-cirrus" created

Wait a few seconds, or keep trying until the status changes from Pending to Running

$ ./cluster/virtctl.sh vnc vm-pvc-cirrus

Note, I am assuming you have virt-viewer installed at this point, if not, install it.

Reset

To reset everything back to a default development cluster run:

$ make cluster-down && make cluster-up && make cluster-sync

Terms/Acronyms

  • CDI: Containerized Data Importer
  • PV: Persistent Volume
  • PVC: Persistent Volume Claim
  • OVM: Offline Virtual Machine
  • VMI: Virtual Machine Image (Immutable disk image, somewhat equivalent to template in oVirt)
  • VMPV: Virtual Machine Persistent Volume (The actual disk used by the VM)

Resources

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