Skip to content

Commit

Permalink
lab structure
Browse files Browse the repository at this point in the history
  • Loading branch information
christofluethi committed Aug 7, 2024
1 parent a0d1677 commit fd4767b
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 21 deletions.
7 changes: 7 additions & 0 deletions config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ enabledModule = "base"
# Enable Lunr.js offline search
offlineSearch = true

# kubevirt lab variables
labsfoldername = "labs"
labsubfolderprefix = "lab"
maxlabnumber = 7

cirrosContainerDiskImage = "quay.io/kubevirt/cirros-container-disk-demo"

[params.ui]
# Enable to show the side bar menu in its compact state.
sidebar_menu_compact = false
Expand Down
61 changes: 41 additions & 20 deletions content/en/docs/01/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "1. Lab Environment"
weight: 1
labfoldernumber: "01"
sectionnumber: 1
---

Expand All @@ -12,7 +13,29 @@ sectionnumber: 1

## Webshell

The provided lab environment contains an Eclipse Theia IDE webshell. Within this webshell you can open a terminal with `Terminal > New Terminal` or `Ctrl+Shift+^`. The available environment contains the needed tools like `kubectl` and `virtctl` as well as the configuration needed to access the kubernetes cluster.
The provided lab environment contains an _Eclipse Theia IDE_[^1]. Your IDE will look something like this:

![Eclipse Theia IDE](theia.png)

- On the left side you can open the file explorer
- The Terminal is accessible using `Ctrl+Shit+^` or using the Menubar `Terminal > New Terminal`

The available environment in the webshell contains all the needed tools like `kubectl` and `virtctl` as well as
the configuration needed to access the kubernetes cluster. If you have a terminal running you can interact with the
kubernetes cluster. For example, you can list your context or get the pods of the current namespace:

```shell
theia(user4) /home/project $ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
local local local user4

theia(user4) /home/project $ kubectl get pods
NAME READY STATUS RESTARTS AGE
user4-webshell-885dbc579-lwhtd 2/2 Running 0 11d
```

You can create files within your webshell or using the file explorer. Using the shell they will show up in the file
explorer and vice versa. Your workplace is persistent and is available for the whole training duration.

### Exiting a console of a virtual machine

Expand Down Expand Up @@ -62,8 +85,18 @@ kubectl config use-context local
Some prefer to explicitly select the Namespace for each `kubectl` command by adding `--namespace <namespace>` or `-n <namespace>`.
{{% /alert %}}


## General Lab Notes

### Placeholders

In this lab we will use the following placeholders or naming conventions

Placeholders:

- `$USER` your username (for example `user4`)


### Hints

We usually provide help for a task you have to complete. For example if you have to implement a method you most likely find the solution in a _Task Hint_ like this one:
Expand All @@ -72,7 +105,6 @@ We usually provide help for a task you have to complete. For example if you have
Your yaml should look like this:

```yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: kubevirtvm
Expand All @@ -81,23 +113,12 @@ spec:
template:
spec:
domain:
devices:
disks:
- name: containerdisk
disk:
bus: virtio
interfaces:
- name: default
masquerade: {}
resources:
requests:
memory: 64M
networks:
- name: default
pod: {}
volumes:
- name: containerdisk
containerDisk:
image: quay.io/kubevirt/cirros-container-disk-demo
devices: {}
memory:
guest: 64Mi
resources: {}
status: {}
```
{{% /details %}}
[^1]: [Eclipse Theia IDE Project](https://theia-ide.org/)
Binary file added content/en/docs/01/theia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions content/en/docs/02/21_create-vm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
title: "2.1 Create a VM"
weight: 210
labfoldernumber: "02"
sectionnumber: 2.1
description: >
Create your first VirtualMachine
---


## Creating a Virtual Machine

To create a Virtual Machine in our kubernetes cluster we have to create and apply a `VirtualMachine` yaml manifest.

This is a very basic example of a bootable virtual machine manifest.

```yaml
kind: VirtualMachine
metadata:
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-firstvm
spec:
running: false
template:
spec:
domain:
devices: {}
resources:
requests:
memory: 64M
```
{{% alert title="Note" color="info" %}}
A VirtualMachine yaml requires a memory resource specification. Therefore, we always have `spec.domain.resources.requests.memory` set.
You may also use `spec.domain.memory.guest` or `spec.domain.memory.hugepages.size` as a resource specification.
{{% /alert %}}

### {{% task %}} Review VirtualMachine manifest

Do you see any problems with the specification above? Try to answer the following questions:

- What happens when you run this vm?
- What is required to successfully boot machine?

{{% details title="Task Hint" %}}
Our created manifest does not contain any bootable devices. Our vm is able to start, but it will just hang as there are
no bootable devices available.

![No bootable device](../no-bootable-device.png)

Having a bootable disk within your yaml specification is all you need to start the vm. However, as there is no network
interface specified which is connected to the underlying network our system would not be capable of interacting with the
outside world.
{{% /details %}}

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

Create a file `vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-firstvm.yaml` with the content yaml
content from above. Starting from the basic manifest you need to add a bootable disk for your vm and a network and
interface specification. The easiest way is to use an ephemeral `containerDisk` mountable as a volume. Regarding the
network we connect our VM to the underlying kubernetes default network.

```yaml
spec:
template:
spec:
domain:
devices:
disks:
- name: containerdisk
disk:
bus: virtio
interfaces:
- name: default
masquerade: {}
networks:
- name: default
pod: {}
volumes:
- name: containerdisk
containerDisk:
image: {{% param "cirrosContainerDiskImage" %}}
```

Make sure you implement the required parts for a container disk and the network interface specification in you VM manifest.

{{% details title="Task Hint" %}}
Your yaml should look like this:
```yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-firstvm
spec:
running: false
template:
spec:
domain:
devices:
disks:
- name: containerdisk
disk:
bus: virtio
interfaces:
- name: default
masquerade: {}
resources:
requests:
memory: 64M
networks:
- name: default
pod: {}
volumes:
- name: containerdisk
containerDisk:
image: quay.io/kubevirt/cirros-container-disk-demo
```
{{% /details %}}

### {{% task %}} Create the VirtualMachine

Since you have completed the yaml configuration for the VM it's now time to create it our VM in the kubernetes cluster.

```shell
kubectl create -f testvm.yaml {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-firstvm.yaml
```

The output should be:

```shell
virtualmachine.kubevirt.io/lab02-firstvm created
```



Loading

0 comments on commit fd4767b

Please sign in to comment.