I returned a few hours ago from Naples after my usual Christmas trip, and I decided to write an article about the progress made with KubeVirt, particularly the integration of KubeVirt into KubeInvaders. Essentially, I want to reboot virtual machines while playing Space Invaders, just like I currently do with regular pods.
First of all, I needed to check the KubeVirt API, which I found here: https://kubevirt.io/api-reference/
For my purpose I need https://kubevirt.io/api-reference/v1.4.0/operations.html#_v1restart
PUT /apis/subresources.kubevirt.io/v1/namespaces/{namespace}/virtualmachines/{name}/restart
Description
Restart a VirtualMachine object.
The other API function I need is the list of virtual machines for a namespace, in order to discover all the virtual machines during the game.
GET /apis/kubevirt.io/v1/namespaces/{namespace}/virtualmachines
Description
Get a list of VirtualMachine objects.
Then, I needed to create a role to allow my service account to reboot the VMs.
I like Kubernetes RBAC, as it allows me to grant permissions specifically for rebooting VMs. Below is the ClusterRole:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
namespace: default
name: kubevirt-vm-restart-role
rules:
- apiGroups: ["subresources.kubevirt.io"]
resources: ["virtualmachines/restart"]
verbs: ["update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubevirt-vm-restart-binding
namespace: default
subjects:
- kind: ServiceAccount
name: kubeinvaders
namespace: kubeinvaders
roleRef:
kind: ClusterRole
name: kubevirt-vm-restart-role
apiGroup: rbac.authorization.k8s.io
Because the game will now support both pods and VMs, I decided to add a legend to represent the different statuses of the objects I want to observe and add some special keys for set the game for discovery virtual machines
# Controls and Options
h => Enable or disable help
s => Enable or disable shuffle for aliens
n => Change the namespace
p => Display pods switch
c => Display nodes switch
v => Display virtual machines (kubevirt) switch
Obviously, it is important to press ‘p’ to disable the discovery of the pods in order to avoid killing the virt-launcher pod and to focus only on the VMs.
I have prepared two VMs in my first post related to KubeVirt that I used for testing this feature. During the test, I observed this command.
[root@node1 ~]# kubectl get vms
NAME AGE STATUS READY
ubuntu-bionic 23d Running True
vm-d9f5z 23d Stopped False
I recorded this short video where I have a shell on the right in which I observe the list and status of the VMs in the default namespace. I position myself on the game console, removing the pods from the visualization (by pressing the “p” key) and enabling the virtual machines (by pressing the “v” key). Then, I launched some missiles towards the alien representing my running VM called “ubuntu-bionic,” and I saw its state change (i.e., the color of the alien changes).
Naturally, performing chaos engineering on the pods makes much more sense, but I believe setting up resilience tests for virtual machines in Kubernetes also makes sense to observe the reboot and scheduling speed, as well as to test distributed systems migrated to Kubernetes.
I released this new feature that you can use by installing k-inv through Helm.
helm repo add kubeinvaders https://lucky-sideburn.github.io/helm-charts/
helm repo update
kubectl create namespace kubeinvaders
# With ingress and TLS enabled
helm install --set-string config.target_namespace="default\,namespace1\,namespace2" --set ingress.enabled=true --set ingress.hostName=kubeinvaders.local --set deployment.image.tag=latest -n kubeinvaders kubeinvaders kubeinvaders/kubeinvaders --set ingress.tls_enabled=true
Thank you for your attention!