Skip to content

Commit

Permalink
Roll-up of updates to migrate from Kata- to Killer- coda (#35)
Browse files Browse the repository at this point in the history
* Basic migration from kata to killer coda

Signed-off-by: cwilkers <[email protected]>

* Updates for Killercoda to 101 scenario

- Added structure to sort and title scenarios in KC interface
- Updated to remove or change mentions of KataCoda

Signed-off-by: cwilkers <[email protected]>

* Bumping clusters to two nodes after failing 101 scenario

Signed-off-by: cwilkers <[email protected]>

* Updating migration scenario to use fore/background scripts

Signed-off-by: cwilkers <[email protected]>

* Scripts must be in scenario tree

Signed-off-by: cwilkers <[email protected]>

* Script updates

Signed-off-by: cwilkers <[email protected]>

* Updates for newer ubuntu and k8s

Signed-off-by: cwilkers <[email protected]>

* Quieter download for debug and ssh fix

Signed-off-by: cwilkers <[email protected]>

* Script fine-tuning

Signed-off-by: cwilkers <[email protected]>

* CDI scenario basic updates to kllr

Signed-off-by: cwilkers <[email protected]>

* Install HPP from newer operator

Signed-off-by: cwilkers <[email protected]>

* Visibility updates for 101 scenario

Signed-off-by: cwilkers <[email protected]>

* Add colorized prompt to other scen

Signed-off-by: cwilkers <[email protected]>

* Make CDI better

Signed-off-by: cwilkers <[email protected]>

* Fine tuning CDI environment

Signed-off-by: cwilkers <[email protected]>

* Changed HPP to script

Signed-off-by: cwilkers <[email protected]>

* Change Fedora to Cirros

Signed-off-by: cwilkers <[email protected]>

* Unify scenario descriptions

Signed-off-by: cwilkers <[email protected]>

* Small cluster performance updates

Signed-off-by: cwilkers <[email protected]>

* Move node taint to background script so install can make use of both nodes

Signed-off-by: cwilkers <[email protected]>

* Update front page to include only 101 example

Signed-off-by: cwilkers <[email protected]>

* amend! Updating migration scenario to use fore/background scripts

Updating migration scenario to use fore/background scripts

Signed-off-by: cwilkers <[email protected]>
  • Loading branch information
cwilkers authored Jul 27, 2022
1 parent 04653e4 commit 4b4f3db
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 244 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Interactive Katacoda Scenarios
# Interactive Killercoda Scenarios

[![](http://shields.katacoda.com/katacoda/kubevirt/count.svg)](https://www.katacoda.com/kubevirt "Get your profile on Katacoda.com")

Visit https://www.katacoda.com/kubevirt to view the profile and interactive scenarios
Visit https://killercoda.com/kubevirt to view the profile and interactive scenarios

### Writing Scenarios
Visit https://www.katacoda.com/docs to learn more about creating Katacoda scenarios
Visit https://killercoda.com/creators to learn more about creating Killercoda scenarios

For examples, visit https://github.com/katacoda/scenario-example
For examples, visit https://github.com/killercoda/scenario-examples
12 changes: 6 additions & 6 deletions kubevirt-101/index.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"pathwayTitle": "KubeVirt",
"title": "First steps with KubeVirt",
"description": "KubeVirt is a virtual machine management add-on for Kubernetes. Deploy it and play with it in a hosted sandboxed interactive environment.",
"title": "Take your first steps with KubeVirt",
"description": "KubeVirt is a virtual machine management add-on for Kubernetes. Deploy KubeVirt and a small virtual machine in this interactive scenario.",
"time": "5min",
"difficulty": "beginner",
"details": {
"steps": [
{
"title": "Launch cluster and deploy KubeVirt",
"title": "Deploy KubeVirt",
"text": "step1.md"
},
{
"title": "Create and use your first VM",
"title": "Create and run your first VM",
"text": "step2.md"
}
],
"intro": {
"text": "intro.md",
"code": "set-env.sh"
"foreground": "setup.sh"
},
"finish": {
"text": "finish.md"
Expand All @@ -27,6 +27,6 @@
"uilayout": "terminal"
},
"backend": {
"imageid": "kubernetes-cluster-running:1.18"
"imageid": "kubernetes-kubeadm-2nodes"
}
}
1 change: 0 additions & 1 deletion kubevirt-101/set-env.sh

This file was deleted.

5 changes: 5 additions & 0 deletions kubevirt-101/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

export PS1="\[\e[1;33m\]\h $ \[\e[1;36m\]"
trap 'echo -ne "\e[0m"' DEBUG
echo
56 changes: 34 additions & 22 deletions kubevirt-101/step1.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
### Wait for the Kubernetes cluster to be ready
# Deploy KubeVirt

Before we can start, we need to wait for the Kubernetes cluster to be ready (a command prompt will appear once it's ready).
Deploy the KubeVirt operator [^1] using the latest KubeVirt version.

#### Deploy KubeVirt
[^1]: An Operator is a method of packaging, deploying, and managing a Kubernetes application. A Kubernetes application is one that is deployed on Kubernetes and managed using the Kubernetes APIs and kubectl tooling. You can think of Operators as the runtime that manages this type of application on Kubernetes. If you want to learn more about Operators you can check the [Kubernetes documentation](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)

Deploy the KubeVirt operator[^1] using the latest KubeVirt version.

[^1] An Operator is a method of packaging, deploying, and managing a Kubernetes application. A Kubernetes application is one that is deployed on Kubernetes and managed using the Kubernetes APIs and kubectl tooling. You can think of Operators as the runtime that manages this type of application on Kubernetes. If you want to learn more about Operators you can check the [Kubernetes documentation](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)

Normally, we would query GitHub's API to get the latest available release:

`export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo $KUBEVIRT_VERSION`

Note: Due to Katacoda supporting an older version of Kubernetes (1.18) than required for recent KubeVirt versions, we will instead set the KUBEVIRT_VERSION environment variable to 0.49.0.
Here, we query GitHub's API to get the latest available release:
(click on the text to automatically execute the commands on the console):

`export KUBEVIRT_VERSION=v0.49.0`{{execute}}
```
export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo $KUBEVIRT_VERSION
```{{execute}}
Run the following command to deploy the KubeVirt Operator:
`kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml`{{execute}}
Now let's deploy KubeVirt by creating a Custom Resource that will trigger the 'operator' reaction and perform the deployment:
Now deploy KubeVirt by creating a Custom Resource that will trigger the 'operator' reaction and perform the deployment:
`kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml`{{execute}}
Next, we need to configure KubeVirt to use software emulation for virtualization. This is necessary for the Katacoda environment, but results in poor performance, so avoid this step in production environments.
Next, we need to configure KubeVirt to use software emulation for virtualization. This is necessary for the course environment but results in poor performance so avoid this step in production environments.
`kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true}}}}'`{{execute}}
# Install Virtctl
While we are waiting for the KubeVirt operator to start up all its Pods, we can take some time to download the client we will need to use in the next step.
_virtctl_ is a client utility that helps interact with VM's (start/stop/console, etc):
`wget -O virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64`{{execute}}
`chmod +x virtctl`{{execute}}
# Wait for KubeVirt deployment to finalize
Let's check the deployment:
`kubectl get pods -n kubevirt`{{execute}}
Once it's ready, it will show something similar to:
~~~
```
controlplane $ kubectl get pods -n kubevirt
NAME READY STATUS RESTARTS AGE
virt-api-7fc57db6dd-g4s4w 1/1 Running 0 3m
Expand All @@ -45,14 +51,20 @@ virt-controller-6849d45bcc-cmfzk 1/1 Running 0 3m
virt-handler-fvsqw 1/1 Running 0 3m
virt-operator-5649f67475-gmphg 1/1 Running 0 4m
virt-operator-5649f67475-sw78k 1/1 Running 0 4m
~~~
```
#### Install Virtctl
As there are multiple deployments involved, the best way to determine whether the operator is fully installed is to check the operator's Custom Resource itself:
`kubectl -n kubevirt get kubevirt`{{execute}}
Once fully deployed, this will look like:
```
NAME AGE PHASE
kubevirt 3m Deployed
```
`virtctl` is a client utility that helps interact with VM's (start/stop/console, etc):
`wget -O virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64`{{execute}}
`chmod +x virtctl`{{execute}}
Now everything is ready to continue and launch a VM.
54 changes: 20 additions & 34 deletions kubevirt-101/step2.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,60 @@
#### Deploy a VM
# Deploy a Virtual Machine

The command below applies a YAML definition of a virtual machine into our current Kubernetes environment, defining the VM name, the resources required (disk, CPU, memory), etc. You can take a look at the [vm.yaml](https://kubevirt.io/labs/manifests/vm.yaml) file if you have interest in knowing more about a virtual machine definition:
The command below applies a YAML definition of a virtual machine into the current Kubernetes environment, defining the VM name, the resources required (disk, CPU, memory), etc. You can take a look at the [vm.yaml](https://kubevirt.io/labs/manifests/vm.yaml) file if you have interest in knowing more about a virtual machine definition:

`kubectl apply -f https://kubevirt.io/labs/manifests/vm.yaml`{{execute}}

We are creating a Virtual Machine in the same way as we would create any other Kubernetes resource thanks to what KubeVirt has enabled in our environment. Now we have a Virtual Machine as a Kubernetes resource.
We are creating a Virtual Machine in the same way as we would create any other Kubernetes resource thanks to the KubeVirt operator in our environment. Now we have a Virtual Machine as a Kubernetes resource.

After the vm resource has been created, you can manage the VMs with standard 'kubectl' commands:

```
$ kubectl get vms
$ kubectl get vms -o yaml testvm
```

Check that the VM is defined (using commands above):

`kubectl get vms`{{execute}}

`kubectl get vms -o yaml testvm | grep -E 'running:.*|$'`{{execute}}

Notice from the output that the VM is not running yet.

To start a VM, `virtctl` should be used:
To start a VM, use _virtctl_ with the _start_ verb:

`./virtctl start testvm`{{execute}}

Now you can check again the VM status:
Again, check the VM status:

`kubectl get vms`{{execute}}

A `VirtualMachine` resource contains a VM's definition and status. An [instance](https://kubevirt.io/user-guide/virtual_machines/virtual_machine_instances/) of a running VM has an additional associated resource, a `VirtualMachineInstance`.
A _VirtualMachine_ resource contains a VM's definition and status. An [instance](https://kubevirt.io/user-guide/virtual_machines/virtual_machine_instances/) of a running VM has an additional associated resource, a _VirtualMachineInstance_.

Once the VM is running you can inspect its status:

```
$ kubectl get vmis
$ kubectl get vmis -o yaml testvm
```

`kubectl get vmis`{{execute}}

Once it's ready, the command above will print something like:
Once it is ready, the command above will print something like:

~~~
controlplane $ kubectl get vmis
```
NAME AGE PHASE IP NODENAME
testvm 1m Running 10.32.0.11 controlplane
~~~
```

#### Accessing VMs (serial console & vnc)
# Access a VM (serial console & vnc)

Now that a VM is running you can access its serial console:
Now that the VM is running you can access its serial console:

**WARNING:** in some browser environments you will not be able to escape the serial console on Katacoda.
**WARNING:** in some OS and browser environments you may not be able to escape the serial console in this course.

**NOTE:** `^]` means: press the "CTRL" and "]" keys to escape the console.
**NOTE:** _^]_ means: press the "CTRL" and "]" keys to escape the console.

~~~sh
# Connect to the serial console
$ ./virtctl console testvm
~~~
`./virtctl console testvm`{{execute}}

If you opened the serial console within Katacoda and you can't escape from it by pressing `^]`, you can click on the `+` close to 'Terminal' to start a new shell there and be able to continue with the following steps in the shutdown and cleanup section.
If you opened the serial console within the Killercoda course environment and you can't escape from it by pressing _^]_, you can click on the _+_ at the top of the terminal window to start a new shell. You should be able to continue with the following steps in the shutdown and cleanup section.

In environments where VNC client access is available, the graphical console of a VM can be accessed with the [virtctl vnc](https://kubevirt.io/user-guide/virtual_machines/graphical_and_console_access/#accessing-the-graphical-console-vnc) command.

#### Shutdown and cleanup
# Shutdown and cleanup

Shutting down a VM also employs the `virtctl` command:
As with starting, stopping a VM also may be accomplished with the _virtctl_ command:

`./virtctl stop testvm`{{execute}}

Finally, the VM can be deleted using:
Finally, the VM can be deleted as any other Kubernetes resource using _kubectl_:

`kubectl delete vms testvm`{{execute}}
9 changes: 9 additions & 0 deletions kubevirt-cdi/foreground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
until kubectl -n kubevirt wait --for=jsonpath='{.status.phase}'=Deployed kubevirt/kubevirt --timeout 9m
do
sleep 30
done

export PS1="\[\e[1;33m\]\h $ \[\e[1;36m\]"
trap 'echo -ne "\e[0m"' DEBUG

echo "KubeVirt is deployed"
15 changes: 8 additions & 7 deletions kubevirt-cdi/index.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"pathwayTitle": "KubeVirt",
"title": "Experiment with CDI",
"description": "CDI is an utility designed to import Virtual Machine images for use with Kubevirt, experiment with it on this Lab",
"description": "CDI is a utility designed to import Virtual Machine images for use with Kubevirt. Deploy CDI and an image based VM in this interactive scenario",
"time": "10min",
"difficulty": "beginner",
"details": {
"intro": {
"text": "intro.md",
"background": "install_kubevirt.sh",
"foreground": "foreground.sh"
},
"steps": [
{
"title": "Launch cluster and deploy KubeVirt",
"title": "Install CDI",
"text": "step1.md"
},
{
"title": "Use CDI to import and start a VM",
"text": "step2.md"
}
],
"intro": {
"text": "intro.md",
"code": "set-env.sh"
},
"finish": {
"text": "finish.md"
}
Expand All @@ -27,6 +28,6 @@
"uilayout": "terminal"
},
"backend": {
"imageid": "kubernetes-cluster-running:1.18"
"imageid": "kubernetes-kubeadm-2nodes"
}
}
27 changes: 27 additions & 0 deletions kubevirt-cdi/install_kubevirt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

kubectl taint node controlplane node-role.kubernetes.io/control-plane:NoSchedule-
kubectl taint node controlplane node-role.kubernetes.io/master:NoSchedule-

export KUBEVIRT_VERSION=$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | jq -r .tag_name)
echo Installing Kubevirt $KUBEVIRT_VERSION

kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
kubectl -n kubevirt scale deployment/kubevirt-operator --replicas=1

kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml

kubectl -n kubevirt patch kubevirt kubevirt --type=merge --patch '{"spec":{"configuration":{"developerConfiguration":{"useEmulation":true,"featureGates":["LiveMigration"]}}}}'
kubectl -n kubevirt patch kubevirt/kubevirt --type=merge --patch='{"spec": {"infra": {"replicas": 1}}}'

curl -sL https://raw.githubusercontent.com/kubevirt/hostpath-provisioner/main/deploy/kubevirt-hostpath-provisioner.yaml \
| sed 's/v1beta1/v1/' | kubectl create -f -

kubectl annotate storageclass kubevirt-hostpath-provisioner storageclass.kubernetes.io/is-default-class=true

curl -sLo virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64

sudo install -m 0755 virtctl /usr/local/bin/virtctl
rm -f virtctl

echo "StrictHostKeyChecking=no" > ${HOME}/.ssh/config
1 change: 0 additions & 1 deletion kubevirt-cdi/set-env.sh

This file was deleted.

Loading

0 comments on commit 4b4f3db

Please sign in to comment.