Skip to content

Commit

Permalink
Merge pull request #14 from acend/philipona/second-interation
Browse files Browse the repository at this point in the history
Feedback round 2
  • Loading branch information
phil-pona authored Sep 28, 2024
2 parents c90fee0 + 3859311 commit 61662bf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 51 deletions.
14 changes: 12 additions & 2 deletions content/en/docs/initialize-vms-with-startup-scripts/cloud-init.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ spec:
networks:
- name: default
pod: {}
tolerations:
- effect: NoSchedule
key: baremetal
operator: Equal
value: "true"
volumes:
- name: containerdisk
containerDisk:
Expand Down Expand Up @@ -245,6 +250,11 @@ spec:
networks:
- name: default
pod: {}
tolerations:
- effect: NoSchedule
key: baremetal
operator: Equal
value: "true"
volumes:
- name: containerdisk
containerDisk:
Expand All @@ -258,7 +268,7 @@ spec:
Make sure you create your VM with:
```bash
kubectl create -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-cloudinit.yaml --namespace=$USER
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-cloudinit.yaml --namespace=$USER
```

Start the VM and verify whether logging in with the defined user and password works as expected.
Expand Down Expand Up @@ -353,7 +363,7 @@ http {
```

{{% details title="Solution" %}}
Your cloud-init configuration will look like this:
Your cloud-init configuration (`cloudinit-userdata.yaml`) will look like this:
```yaml
#cloud-config
password: kubevirt
Expand Down
12 changes: 11 additions & 1 deletion content/en/docs/initialize-vms-with-startup-scripts/ignition.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ spec:
networks:
- name: default
pod: {}
tolerations:
- effect: NoSchedule
key: baremetal
operator: Equal
value: "true"
volumes:
- name: containerdisk
containerDisk:
Expand Down Expand Up @@ -190,6 +195,11 @@ spec:
networks:
- name: default
pod: {}
tolerations:
- effect: NoSchedule
key: baremetal
operator: Equal
value: "true"
volumes:
- name: containerdisk
containerDisk:
Expand All @@ -203,7 +213,7 @@ spec:
Create your VM with:
```bash
kubectl create -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-ignition.yaml --namespace=$USER
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-ignition.yaml --namespace=$USER
```

Start the VM and verify whether logging in with the defined user and password works as expected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,16 @@ Deploy two VMs with different instance types:
* Deploy a cirros VM using an `o` class instancetype and the same preference.
* rite the VM specification in `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros.yaml`


{{% onlyWhenNot tolerations %}}

{{% details title="Task Hint: Solution" %}}
{{% details title="Solution" %}}
`{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros.yaml` specification:
```yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: u1-cirros
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros
spec:
running: false
instancetype:
Expand All @@ -356,7 +357,7 @@ spec:
metadata:
labels:
kubevirt.io/size: nano
kubevirt.io/domain: u1-cirros
kubevirt.io/domain: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros
spec:
domain:
devices:
Expand All @@ -383,7 +384,7 @@ spec:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: o1-cirros
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros
spec:
running: false
instancetype:
Expand All @@ -396,7 +397,7 @@ spec:
metadata:
labels:
kubevirt.io/size: nano
kubevirt.io/domain: o1-cirros
kubevirt.io/domain: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros
spec:
domain:
devices:
Expand All @@ -423,13 +424,13 @@ spec:
Don't forget the `tolerations` from the setup chapter to make sure the VM will be scheduled on one of the baremetal nodes.
{{% /alert %}}

{{% details title="Task Hint: Solution" %}}
{{% details title="Solution" %}}
`{{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros.yaml` specification:
```yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: u1-cirros
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros
spec:
running: false
instancetype:
Expand All @@ -442,7 +443,7 @@ spec:
metadata:
labels:
kubevirt.io/size: nano
kubevirt.io/domain: u1-cirros
kubevirt.io/domain: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros
spec:
domain:
devices:
Expand Down Expand Up @@ -474,7 +475,7 @@ spec:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
name: o1-cirros
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros
spec:
running: false
instancetype:
Expand All @@ -487,7 +488,7 @@ spec:
metadata:
labels:
kubevirt.io/size: nano
kubevirt.io/domain: o1-cirros
kubevirt.io/domain: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros
spec:
domain:
devices:
Expand Down Expand Up @@ -519,10 +520,10 @@ spec:
Apply and start both VMs with

```bash
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_u1-cirros.yaml --namespace=$USER
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_o1-cirros.yaml --namespace=$USER
virtctl start u1-cirros
virtctl start o1-cirros
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros.yaml --namespace=$USER
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vm_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros.yaml --namespace=$USER
virtctl start {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros
virtctl start {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros
```
{{% /details %}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Your Instancetype should look like this (labels and annotations are optional):
apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
name: lab04-o1-pico
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico
annotations:
instancetype.kubevirt.io/description: |-
The O Series is based on the U Series, with the only difference
Expand All @@ -55,7 +55,7 @@ spec:
Create your resource with:
```bash
kubectl create -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vmf_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico.yaml --namespace=$USER
kubectl apply -f {{% param "labsfoldername" %}}/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}/vmf_{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico.yaml --namespace=$USER
```

And verify whether the creation was successful:
Expand All @@ -78,36 +78,16 @@ kubectl get vmf {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}
```

The output will be similar to this one:
```bash
```yaml
apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
annotations:
instancetype.kubevirt.io/description: |-
The U Series is quite neutral and provides resources for
general purpose applications.

*U* is the abbreviation for "Universal", hinting at the universal
attitude towards workloads.

VMs of instance types will share physical CPU cores on a
time-slice basis with other VMs.
instancetype.kubevirt.io/displayName: General Purpose
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"instancetype.kubevirt.io/v1beta1","kind":"VirtualMachineInstancetype","metadata":{"annotations":{"instancetype.kubevirt.io/description":"The U Series is quite neutral and provides resources for\ngeneral purpose applications.\n\n*U* is the abbreviation for \"Universal\", hinting at the universal\nattitude towards workloads.\n\nVMs of instance types will share physical CPU cores on a\ntime-slice basis with other VMs.","instancetype.kubevirt.io/displayName":"General Purpose"},"labels":{"instancetype.kubevirt.io/class":"general.purpose","instancetype.kubevirt.io/cpu":"1","instancetype.kubevirt.io/icon-pf":"pficon-server-group","instancetype.kubevirt.io/memory":"256Mi","instancetype.kubevirt.io/vendor":"kubevirt-basics-training","instancetype.kubevirt.io/version":"1"},"name":"lab04-u1-pico","namespace":"user4"},"spec":{"cpu":{"guest":1},"memory":{"guest":"256Mi"}}}
creationTimestamp: "2024-08-14T12:10:36Z"
creationTimestamp: "2024-09-25T09:25:35Z"
generation: 1
labels:
instancetype.kubevirt.io/class: general.purpose
instancetype.kubevirt.io/cpu: "1"
instancetype.kubevirt.io/icon-pf: pficon-server-group
instancetype.kubevirt.io/memory: 256Mi
instancetype.kubevirt.io/vendor: kubevirt-basics-training
instancetype.kubevirt.io/version: "1"
name: lab04-u1-pico
namespace: user4
resourceVersion: "16264315"
uid: 33cfc789-d041-4a56-bb28-26605759a890
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-pico
namespace: <user>
resourceVersion: "55713159"
uid: 14d414b7-b1f8-4b0d-af48-fb84340545c9
spec:
cpu:
guest: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Whenever a VM referencing an instancetype or preference is created, the definiti

This field ensures that our VirtualMachine knows the original specification even when the type or preference would be changed. This ensures that there are no accidental changes of the VM resources or preferences.

Use the following command to display the vm resource, you will find the reference to the revision under `spec.instancetype.revisionName`:
```bash
kubectl get vm {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros -o yaml --namespace=$USER
```

Example of a VM with a `revisionName`:
```yaml
[...]
Expand All @@ -33,27 +38,48 @@ kubectl get controllerrevision --namespace=$USER

```
NAME CONTROLLER REVISION AGE
{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros-cirros-v1beta1-fa1da1cd-7e10-4e89-a8ac-5bded8f7129e-1 virtualmachine.kubevirt.io/lab04-o1-cirros 0 2h
{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros-cirros-v1beta1-fa1da1cd-7e10-4e89-a8ac-5bded8f7129e-1 virtualmachine.kubevirt.io/lab04-u1-cirros 0 2h
{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros-cirros-v1beta1-fa1da1cd-7e10-4e89-a8ac-5bded8f7129e-1 virtualmachine.kubevirt.io/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros 0 2h
{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros-cirros-v1beta1-fa1da1cd-7e10-4e89-a8ac-5bded8f7129e-1 virtualmachine.kubevirt.io/{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros 0 2h
[...]
```

If we want to explicitly change the Instancetype or preference we have to remove the `revisionName` attribute completely otherwise it will reject the change.

The easies way is to edit the resource directly is:
```bash
The request is invalid: spec.instancetype.revisionName: the Matcher Name has been updated without updating the RevisionName
```

If we want to change the Instancetype in the resource and reapply the changes using `kubectl apply -f` we need to set the RevisionName to `null`

```yaml
[...]
spec:
instancetype:
kind: VirtualMachineClusterInstancetype
name: u1.nano
revisionName: null
[...]
```

When editing the resource directly, we can simply remove the `revisionName`:
```bash
kubectl edit vm {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros --namespace=$USER
```

An alternative would be patching the resource directly with:
Or alternatively, patch the resource directly with:
```bash
kubectl patch vm {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros --type merge --patch '{"spec":{"instancetype":{"kind":"<KIND>","name":"<NAME>","revisionName":null}}}' --namespace=$USER
```


## {{% task %}} Adapt your VMs to use the new instancetype

Edit the VM `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros` and reference the `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-pico` and do the same for the VM `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros` and reference `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico`
Change the InstanceTypes of the two VMs from the current VirtualMachineClusterInstancetype (`u1.nano`) to the InstanceType (`{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-pico` and `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico`)

* `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-cirros`
* `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros`

Use one of the mentioned methods above, to change the resource.

{{% alert title="Note" color="info" %}}
Since so far we were referencing a `VirtualMachineClusterPreference` also change the kind to `VirtualMachineInstancetype` for our new InstanceTypes.
Expand All @@ -68,7 +94,7 @@ The relevant section for the VM `{{% param "labsubfolderprefix" %}}{{% param "la
spec:
instancetype:
kind: VirtualMachineInstancetype
name: lab04-u1-pico
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-u1-pico
```
For `{{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-cirros` it will be:
Expand All @@ -78,6 +104,7 @@ spec:
kind: VirtualMachineInstancetype
name: {{% param "labsubfolderprefix" %}}{{% param "labfoldernumber" %}}-o1-pico
```

{{% /details %}}

Make sure you restart both VMs to reflect the change of their instancetype:
Expand Down

0 comments on commit 61662bf

Please sign in to comment.