Skip to content

Commit 7993204

Browse files
Add workshop showing suspending of virtual machine.
1 parent ab33ac6 commit 7993204

File tree

7 files changed

+274
-0
lines changed

7 files changed

+274
-0
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Suspend Instance
2+
================
3+
4+
This workshop demonstrates using `viertctl` from a workshop session to suspend
5+
the virtual machine created for the workshop session.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
apiVersion: training.educates.dev/v1beta1
2+
kind: Workshop
3+
metadata:
4+
name: "lab-suspend-instance"
5+
spec:
6+
title: "Suspend Instance Test"
7+
description: "Test of suspending a VirtualMachine."
8+
publish:
9+
image: $(image_repository)/labs-kubevirt-testing/lab-suspend-instance-files:$(workshop_version)
10+
workshop:
11+
files:
12+
- image:
13+
url: $(image_repository)/labs-kubevirt-testing/lab-suspend-instance-files:$(workshop_version)
14+
includePaths:
15+
- workshop/**
16+
session:
17+
namespaces:
18+
budget: x-large
19+
limits:
20+
max:
21+
memory: 2.5Gi
22+
applications:
23+
terminal:
24+
enabled: true
25+
layout: split
26+
editor:
27+
enabled: true
28+
console:
29+
enabled: true
30+
examiner:
31+
enabled: true
32+
objects:
33+
- apiVersion: rbac.authorization.k8s.io/v1
34+
kind: Role
35+
metadata:
36+
name: virtctl-user
37+
rules:
38+
- apiGroups:
39+
- kubevirt.io
40+
resources:
41+
- virtualmachines
42+
- virtualmachineinstances
43+
verbs:
44+
- get
45+
- list
46+
- watch
47+
- patch
48+
- update
49+
- apiGroups:
50+
- subresources.kubevirt.io
51+
resources:
52+
- virtualmachineinstances/pause
53+
- virtualmachineinstances/unpause
54+
verbs:
55+
- update
56+
- apiVersion: rbac.authorization.k8s.io/v1
57+
kind: RoleBinding
58+
metadata:
59+
name: virtctl-user
60+
roleRef:
61+
apiGroup: rbac.authorization.k8s.io
62+
kind: Role
63+
name: virtctl-user
64+
subjects:
65+
- kind: ServiceAccount
66+
namespace: $(workshop_namespace)
67+
name: $(service_account)
68+
- apiVersion: secrets.educates.dev/v1beta1
69+
kind: SecretCopier
70+
metadata:
71+
name: $(session_name)-ssh-keys
72+
spec:
73+
rules:
74+
- sourceSecret:
75+
name: $(ssh_keys_secret)
76+
namespace: $(workshop_namespace)
77+
targetNamespaces:
78+
nameSelector:
79+
matchNames:
80+
- $(session_namespace)
81+
targetSecret:
82+
name: ssh-keys
83+
- apiVersion: kubevirt.io/v1
84+
kind: VirtualMachine
85+
metadata:
86+
name: testing
87+
labels:
88+
kubevirt.io/vm: testing
89+
spec:
90+
running: true
91+
template:
92+
metadata:
93+
labels:
94+
kubevirt.io/vm: testing
95+
spec:
96+
terminationGracePeriodSeconds: 30
97+
accessCredentials:
98+
- sshPublicKey:
99+
source:
100+
secret:
101+
secretName: ssh-keys
102+
propagationMethod:
103+
configDrive: {}
104+
domain:
105+
cpu:
106+
cores: 2
107+
resources:
108+
limits:
109+
memory: 2Gi
110+
requests:
111+
memory: 2Gi
112+
devices:
113+
disks:
114+
- name: disk1
115+
disk:
116+
bus: virtio
117+
- disk:
118+
bus: virtio
119+
name: cloudinitdisk
120+
interfaces:
121+
- name: default
122+
masquerade: {}
123+
networks:
124+
- name: default
125+
pod: {}
126+
volumes:
127+
- name: disk1
128+
containerDisk:
129+
image: $(oci_image_cache)/containerdisks/fedora:37
130+
- name: cloudinitdisk
131+
cloudInitConfigDrive:
132+
userData: |-
133+
#cloud-config
134+
password: $(services_password)
135+
chpasswd: { expire: False }
136+
- apiVersion: v1
137+
kind: Service
138+
metadata:
139+
name: testing
140+
spec:
141+
selector:
142+
kubevirt.io/vm: testing
143+
ports:
144+
- name: ssh
145+
protocol: TCP
146+
port: 22
147+
targetPort: 22
148+
- name: http
149+
protocol: TCP
150+
port: 80
151+
targetPort: 80
152+
- name: https
153+
protocol: TCP
154+
port: 443
155+
targetPort: 443
156+
environment:
157+
images:
158+
ingress:
159+
enabled: true
160+
storage: 1Gi
161+
registries:
162+
- urls:
163+
- https://quay.io/containerdisks
164+
onDemand: true
165+
tlsVerify: true
166+
content:
167+
- prefix: "**"
168+
destination: /containerdisks
169+
stripPrefix: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Workshop Overview
3+
---
4+
5+
Wait for virtual machine to be ready.
6+
7+
```examiner:execute-test
8+
name: check-virtual-machine-is-ready
9+
prefix: KubeVirt
10+
title: "Checking virtual machine is ready"
11+
args:
12+
- testing
13+
timeout: 5
14+
retries: .INF
15+
delay: 1
16+
autostart: true
17+
```
18+
19+
Access the virtual machine.
20+
21+
```terminal:execute
22+
command: ssh fedora@testing.{{< param session_namespace >}}
23+
```
24+
25+
Accept the host fingerprint.
26+
27+
```terminal:input
28+
text: yes
29+
```
30+
31+
32+
Exit virtual machine shell.
33+
34+
```terminal:execute
35+
command: exit
36+
```
37+
38+
Suspend virtual machine.
39+
40+
```terminal:execute
41+
session: 2
42+
command: virtctl pause vm testing
43+
```
44+
45+
Check status of virtual machine.
46+
47+
```terminal:execute
48+
session: 2
49+
command: kubectl get vms
50+
```
51+
52+
Confirm that can not access virtual machine.
53+
54+
```terminal:execute
55+
command: ssh fedora@testing.{{< param session_namespace >}}
56+
```
57+
58+
Resume virtual machine.
59+
60+
```terminal:execute
61+
session: 2
62+
command: virtctl unpause vm testing
63+
```
64+
65+
Check status of virtual machine.
66+
67+
```terminal:execute
68+
session: 2
69+
command: kubectl get vms
70+
```
71+
72+
Confirm that can can access virtual machine again.
73+
74+
```terminal:execute
75+
command: ssh fedora@testing.{{< param session_namespace >}}
76+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Workshop Instructions
3+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
title: Workshop Summary
3+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
VM=$1
4+
5+
exec ssh -o "StrictHostKeyChecking no" fedora@$VM.$SESSION_NAMESPACE.svc.$CLUSTER_DOMAIN date
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -eo pipefail
5+
6+
mkdir -p $HOME/bin
7+
8+
VERSION=v1.0.0
9+
ARCH=linux-amd64
10+
11+
curl --silent --fail -L -o $HOME/bin/virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
12+
13+
chmod +x $HOME/bin/virtctl

0 commit comments

Comments
 (0)