Skip to content

Commit

Permalink
Merge pull request #13 from acend/containerized-data-importer
Browse files Browse the repository at this point in the history
Proofread CDI chapter
  • Loading branch information
phil-pona authored Sep 28, 2024
2 parents d195c47 + 25ff2e8 commit c90fee0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 49 deletions.
3 changes: 1 addition & 2 deletions content/en/docs/containerized-data-importer/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ for our KubeVirt VMs.
## Lab Goals

* Know what the Containerized Data Importer is
* Why do we use the Containerized Data Importer
* Understand why we use the Containerized Data Importer
* Import a disk image from a webserver
* Start a VM with an Alpine Cloud Disk Image

30 changes: 18 additions & 12 deletions content/en/docs/containerized-data-importer/alpine-vm.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
---
title: "Using the Alpine Disk"
title: "Using the Alpine disk"
weight: 23
labfoldernumber: "02"
description: >
Create a virtual machine using the provisioned Alpine Cloud Disk Image
---

In the previous section we have provisioned a custom alpine cloud disk image. We will now create a VM which uses this
In the previous section we have provisioned a custom Alpine cloud disk image. We will now create a VM which uses this
disk image.


## {{% task %}} Attach the disk

With your knowledge write a new VirtualMachine manifest named `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine.yaml` in the directory `{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}`.
Write a new VirtualMachine manifest named `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine.yaml` in the directory `{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}`.

{{% alert title="Note" color="info" %}}
This Alpine Cloud Image has cloud-init included. We will need another disk (cloudinitdisk) which configures our environment.
We will look into cloud-init in a later section. For now, just use the cloudinitdisk specification from the snippet below.
{{% /alert %}}

Block needed to reference the pvc as a disk and the `cloudinitdisk`:
Block needed to reference the PVC as a disk and the `cloudinitdisk`:

```yaml
volumes:
- name: alpinedisk
Expand All @@ -33,7 +34,7 @@ Block needed to reference the pvc as a disk and the `cloudinitdisk`:
chpasswd: { expire: False }
```
You will have to reference the `cloudinitdisk` as a second disk in `spec.template.spec.domain.devices.disks`
You will have to reference the `cloudinitdisk` as a second disk in `spec.template.spec.domain.devices.disks`.

{{% onlyWhenNot tolerations %}}

Expand Down Expand Up @@ -140,38 +141,43 @@ spec:

## {{% task %}} Create and start the VM

Create the vm in the kubernetes cluster:
Create the VM on the Kubernetes cluster:

```bash
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine.yaml --namespace=$USER
```

Start your vm with:
Start your VM with:

```bash
virtctl start {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine --namespace=$USER
```


## {{% task %}} Testing the VM

Open the console of your VM:
Open the VM's console:

```bash
virtctl console {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine --namespace=$USER
```

After some time your VM should be successfully be provisioned with the alpine cloud disk image.
You should be able to successfully login with user `alpine` and the configured password.
After some time your VM should be successfully provisioned with the Alpine cloud disk image.
You should be able to successfully log in with user `alpine` and the configured password.


## End of lab

{{% alert title="Cleanup resources" color="warning" %}} {{% param "end-of-lab-text" %}}

Stop your running VM with
Stop your running VM with:

```bash
virtctl stop {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpine --namespace=$USER
```

Delete your DataVolume which will delete the PVC and free the diskspace.
Delete your DataVolume which will delete the PVC and free the diskspace:

```bash
kubectl delete dv {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk --namespace=$USER
```
Expand Down
46 changes: 24 additions & 22 deletions content/en/docs/containerized-data-importer/cdi-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ description: >
Introduction to the Containerized Data Importer
---

The Containerized Data Importer Project[^1] is an independent installed operator. It is primary used to provide a declarative way
to build Virtual Machine Disks on PVCs for KubeVirt VMs. Since the CDI Operator provides the custom resource `DataVolume`
which is an abstraction above a PVC.
The Containerized Data Importer Project[^1] is an independently installed Operator. It is primarily used to provide a declarative way
to build Virtual Machine Disks on PVCs for KubeVirt VMs. The CDI Operator provides the custom resource `DataVolume`
which is an abstraction above the PVC.


## CDI Operator components

{{% alert title="Note" color="info" %}}
The operator has already been installed in the namespace `cdi`. If you want to deploy the operator check the
The Operator has already been installed in Namespace `cdi`. If you want to deploy the Operator, check the
[Deploy](https://github.com/kubevirt/containerized-data-importer?tab=readme-ov-file#deploy-it) section of the CDI documentation.
{{% /alert %}}

You may see the cdi operator components with:
You may see the CDI Operator components with:

```bash
kubectl get pods --namespace cdi
```

The output should similar to:
The output should be similar to the following:

```bash
NAME READY STATUS RESTARTS AGE
cdi-apiserver-5d565ddb6-lrrrk 1/1 Running 0 1d
Expand All @@ -32,11 +34,11 @@ cdi-operator-595bfb44cd-j5s4h 1/1 Running 0 1d
cdi-uploadproxy-7657d8d89d-qth44 1/1 Running 0 1d
```

* **cdi-deployment** - Long-lived cdi controller pod managing the cdi operations.
* **cdi-operator** - the operator pod managing the cdi components.
* **cdi-apiserver** - Issues secure tokens and manages authorization to upload VM disks into pvcs.
* **cdi-uploadproxy** - Handles upload traffic and writes content to correct pvc.
* **cdi-importer** - Short-lived helper pod that imports a VM image to a pvc.
* **cdi-deployment** - Long-lived CDI controller Pod managing the CDI operations
* **cdi-operator** - the Operator Pod managing the CDI components
* **cdi-apiserver** - Issues secure tokens and manages authorization to upload VM disks into PVCs
* **cdi-uploadproxy** - Handles upload traffic and writes content to the correct PVC
* **cdi-importer** - Short-lived helper Pod that imports a VM image to a PVC


## DataVolume manifest
Expand Down Expand Up @@ -67,13 +69,13 @@ spec:
The source location of the data.
* `http` - Download data from a given URL.
* `registry` - Download a Container Disk from a given URL.
* `pvc` - Clone a given pvc referenced by name and namespace to a new pvc.
* `upload` - Provide an upload proxy to receive data from an authenticated client.
* `blank` - Create an empty VM disk.
* `imageio` - Import a VM disk from a running oVirt installation.
* `vddk` - Import a VMware VM disk using vCenter/ESX API.
* `http` - Download data from a given URL
* `registry` - Download a Container Disk from a given URL
* `pvc` - Clone a given PVC referenced by name and Namespace to a new PVC
* `upload` - Provide an upload proxy to receive data from an authenticated client
* `blank` - Create an empty VM disk
* `imageio` - Import a VM disk from a running oVirt installation
* `vddk` - Import a VMware VM disk using vCenter/ESX API


### ContentType
Expand All @@ -87,13 +89,13 @@ Type of the source data. Either `kubevirt` (default) or `archive`.

### Target (Storage/PVC)

You can define the target as `pvc` or `storage`. Both will result in a PVC but there are differences how they work.
You can define the target as `pvc` or `storage`. Both will result in a PVC but there are differences in how they work.

* `pvc` defines that the following configuration is passed directly to the pvc.
* `storage` is similar to pvc but provides some logic to fill in fields for the pvc request. As an example we could omit the storageClassName parameter and CDI will detect the default virtualization storage class if there is one which is annotated by `storageclass.kubevirt.io/is-default-virt-class`.
* `pvc` defines that the following configuration is passed directly to the PVC.
* `storage` is similar to PVC but provides some logic to fill in fields for the PVC request. As an example we could omit the storageClassName parameter and CDI will detect the default virtualization storage class if there is one which is annotated with `storageclass.kubevirt.io/is-default-virt-class`.

This basic configuration provides the flexibility to use CDI as a provisioner for KubeVirt Virtual Machine Disk Images
as well as a provisioner for regular pvcs used with containers.
as well as a provisioner for regular PVCs used with containers.


### Limitations
Expand Down
31 changes: 18 additions & 13 deletions content/en/docs/containerized-data-importer/create-datavolume.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ description: >

## Provisioning a Virtual Machine Disk

In the following lab we will provision a disk from a given url. We will use a `DataVolume` to create the Disk. We then
In the following lab, we will provision a disk from a given url. We will use a `DataVolume` to create the Disk. We then
create a VM with the disk attached.

We want to provision a VM running an Alpine Cloud Image[^1].


## {{% task %}} Write your own DataVolume manifest

Create a file `dv_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk.yaml` in the folder `{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}`and start with the
yaml content from the previous section:
Create a file `dv_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk.yaml` in folder `{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}`and start with the content from the previous section:

```yaml
apiVersion: cdi.kubevirt.io/v1beta1
Expand All @@ -39,14 +38,15 @@ spec:
Now adapt your DataVolume to fulfill the following specifications:
1. Download a Disk Image from a given URL
* Use `{{% param alpineContainerDiskDownload %}}` as URL for the disk image.
2. Create a KubeVirt VM Disk
* Use `{{% param alpineContainerDiskDownload %}}` as URL for the disk image
2. Create a KubeVirt VM disk
3. Requested storage should be 256Mi
4. Name the volume `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk`
5. Set the `accessMode` to `ReadWriteOnce`

{{% details title="Task Hint" %}}
Your yaml should look like this:
Your manifest should look like this:

```yaml
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
Expand All @@ -66,42 +66,47 @@ spec:
```
{{% /details %}}

Before you apply your DataVolume to the cluster check the currently available pvcs.
Before you apply your DataVolume to the cluster, check the currently available PVCs:

```bash
kubectl get pvc --namespace=$USER
```

The output should be similar to:

```bash
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
$USER-webshell Bound pvc-594cf281-4c34-4e7c-b345-2bf2692bbb78 1Gi RWO longhorn <unset> 1d
$USER-webshell-docker Bound pvc-86e4bc75-396f-4630-940e-b0a4b0cf23fa 10Gi RWO longhorn <unset> 1d
```

Now create the DataVolume in the kubernetes cluster with:
Now create the DataVolume on the Kubernetes cluster with:

```bash
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/dv_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk.yaml --namespace=$USER
```

The output should be:

```bash
datavolume.cdi.kubevirt.io/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-alpinedisk created
```

This will trigger the CDI operator which will start an importer pod to provision your pvc. If you are fast enough you may see the pod with:
This will trigger the CDI Operator which will start an importer Pod to provision your PVC. If you are fast enough you may see the Pod with:

```bash
kubectl get pods --namespace=$USER
```

The output should be similar to:

```bash
NAME READY STATUS RESTARTS AGE
importer-prime-36720196-c64a-42d8-8db5-af31b75de034 0/1 ContainerCreating 0 9s
$USER-webshell-885dbc579-lwhtd 2/2 Running 0 1d
```

After some time the pod will complete and your pvc should be provisioned. Let's check for the existence of the pvc.
After some time, the Pod will complete and your PVC should be provisioned. Let's check for the existence of the PVC:

```bash
kubectl get pvc --namespace=$USER
Expand All @@ -121,12 +126,12 @@ user4-webshell-docker Bound pvc-86e4bc75-396f-4630-940e-b0a4b0cf23fa 10Gi

You have successfully provisioned a disk image which is ready to be used within a virtual machine.

We have used the alpine image as it is reasonable small. Would there have been another way to provide the Disk Image for
We have used the Alpine image as it is reasonably small. Would there have been another way to provide the Disk Image for
every participant without the need to download the image multiple times?

{{% details title="Task Hint" %}}
We could have provided a provisioned pvc in a central namespace and create our DataVolume with a `pvc` source and let
the CDI operator clone the central pvc to a pvc your namespace.
We could have provided a provisioned PVC in a central Namespace and created our DataVolume with a `pvc` source, then let
the CDI Operator clone the central PVC to a PVC your Namespace.
{{% /details %}}

[^1]: [Alpine Cloud Image](https://alpinelinux.org/cloud/)

0 comments on commit c90fee0

Please sign in to comment.