The Laboratory Operator (LabOperator) implements the backend logic necessary to spawn new laboratories starting from a predefined template. LabOperator relies on two Kubernetes Custom Resource Definitions (CRDs) which implement the basic APIs:
- Laboratory Template (LabTemplate) defines the size of the execution environment (e.g.; Virtual Machine), its base image and a description. This object is created by professors and read by students, while creating new instances.
- Laboratory Instance (LabInstance) defines an instance of a certain template. The manipulation of those objects triggers the reconciliation logic in LabOperator, which creates/destroy associated resources (e.g.; Virtual Machines).
Both LabTemplates and LabInstances are namespaced.
Before the deploying the operator, we have to add the LabInstance and LabTemplate CRDs. This can be done via the Makefile:
make install
Based on Kubebuilder 2.3, the operator implements the laboratory creation logic of Crownlabs.
Upon the creation of a LabInstance, the operator triggers the creation of the following components:
- Kubevirt VirtualMachine Instance and the logic to access the noVNC instance inside the VM (Service, Ingress)
- An instance of Oauth2 Proxy (Deployment, Service, Ingress) to regulate access to the VM.
All those resources are binded to the LabInstance life-cycle via the OwnerRef property
The only LabOperator requirement is to have Kubevirt deployed. This can be done with the following commands, as reported by the official website:
# On other OS you might need to define it like
export KUBEVIRT_VERSION="v0.34.0"
# Deploy the KubeVirt operator
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
# Only if HW Virtualization is not available
kubectl create configmap kubevirt-config -n kubevirt --from-literal debug.useEmulation=true
# Deploy Kubevirt
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml
To deploy the LabOperator in your cluster, you have to do the following steps.
First, set the desired values in operators/deploy/laboratory-operator/k8s-manifest-example.env
.
Then export the environment variables and generate the manifest from the template using:
cd operators/deploy/laboratory-operator
export $(xargs < k8s-manifest-example.env)
envsubst < k8s-manifest.yaml.tmpl > k8s-manifest.yaml
After the manifest have been correctly generated. You can deploy the labOperator using:
kubectl apply -f k8s-manifest.yaml
LabOperator requires Golang 1.13 and make. To build the operator:
go build ./cmd/laboratory-operator/main.go
After having installed Kubevirt in your testing cluster, you have to deploy the Custom Resource Definitions (CRDs) on the target cluster:
make install
N.B. So far, the readiness check for VirtualMachines is performed by assuming that the operator is running on the same cluster of the Virtual Machines. This prevents the possibility to have ready VMs when testing the operator outside the cluster.