KubeVirt#
k0rdent can deploy child clusters using KubeVirt. Follow these steps to configure and deploy KubeVirt clusters:
-
Install k0rdent
Follow the instructions in Install k0rdent to create a management cluster with k0rdent running.
-
Prepare the KubeVirt Infrastructure Cluster
Follow the instructions in KubeVirt Infrastructure Cluster Preparation to prepare your KubeVirt Infrastructure Cluster.
-
virtctlCLI (optional)If you plan to access KubeVirt VMs directly, install the
virtctlCLI (see theVirtctlsection). -
Create the
Secretwith the base64-encoded KubeVirt Infrastructure Cluster kubeconfig under thedata.kubeconfigkeyReplace
$KUBEVIRT_INFRA_CLUSTER_KUBECONFIG_B64with the base64-encoded kubeconfig of your KubeVirt Infrastructure Cluster.Apply the YAML to your cluster:cat > kubevirt-kubeconfig-secret.yaml << EOF apiVersion: v1 data: kubeconfig: $KUBEVIRT_INFRA_CLUSTER_KUBECONFIG_B64 kind: Secret metadata: name: kubevirt-kubeconfig namespace: kcm-system labels: k0rdent.mirantis.com/component: "kcm" type: Opaque EOFkubectl apply -f kubevirt-kubeconfig-secret.yaml -
Create the k0rdent
CredentialobjectDefine a
Credentialthat references theSecretfrom the previous step. Save this askubevirt-cred.yaml.Note that
.spec.identityRef.namemust match.metadata.nameof theSecretobject created in the previous step.cat > kubevirt-cred.yaml << EOF apiVersion: k0rdent.mirantis.com/v1beta1 kind: Credential metadata: name: kubevirt-cred namespace: kcm-system spec: identityRef: apiVersion: v1 kind: Secret name: kubevirt-kubeconfig namespace: kcm-system EOFApply the YAML to your cluster:
kubectl apply -f kubevirt-cred.yaml -
Create the
ClusterIdentityresource templateConfigMapCreate the k0rdent
ClusterIdentityresource templateConfigMap. As in prior steps, create a YAML file calledkubevirt-kubeconfig-resource-template.yaml:Note
The
ConfigMapname must be exactly$SECRET_NAME-resource-template(in this case,kubevirt-kubeconfig-resource-template). See naming the template configmap for details.Thecat > kubevirt-kubeconfig-resource-template.yaml << EOF apiVersion: v1 kind: ConfigMap metadata: name: kubevirt-kubeconfig-resource-template namespace: kcm-system labels: k0rdent.mirantis.com/component: "kcm" annotations: projectsveltos.io/template: "true" EOFConfigMaponly contains metadata and no data fields. This is expected, because we do not need to template any objects inside child clusters. You can use this object in the future if the need arises.Apply this YAML to your management cluster:
kubectl apply -f kubevirt-kubeconfig-resource-template.yaml -n kcm-system -
Create your first child cluster
To test the configuration, create a YAML file with the specification of your
ClusterDeploymentand save it asmy-kubevirt-cluster-deployment.yaml.You can list the available templates with:
kubectl get clustertemplate -n kcm-systemNAMESPACE NAME VALID kcm-system adopted-cluster-1-0-1 true kcm-system aws-eks-1-0-4 true kcm-system aws-hosted-cp-1-0-21 true kcm-system aws-standalone-cp-1-0-20 true kcm-system azure-aks-1-0-2 true kcm-system azure-hosted-cp-1-0-23 true kcm-system azure-standalone-cp-1-0-20 true kcm-system docker-hosted-cp-1-0-4 true kcm-system gcp-gke-1-0-7 true kcm-system gcp-hosted-cp-1-0-20 true kcm-system gcp-standalone-cp-1-0-18 true kcm-system kubevirt-hosted-cp-1-0-1 true kcm-system kubevirt-standalone-cp-1-0-1 true kcm-system openstack-hosted-cp-1-0-22 true kcm-system openstack-standalone-cp-1-0-22 true kcm-system remote-cluster-1-0-19 true kcm-system vsphere-hosted-cp-1-0-19 true kcm-system vsphere-standalone-cp-1-0-18 trueA
ClusterDeploymentdefinition might look like this:apiVersion: k0rdent.mirantis.com/v1beta1 kind: ClusterDeployment metadata: name: my-kubevirt-cluster-deployment namespace: kcm-system spec: template: kubevirt-standalone-cp-1-0-1 # name of the clustertemplate credential: $CREDENTIAL_NAME propagateCredentials: false config: clusterLabels: {} clusterAnnotations: {} controlPlaneNumber: 1 workersNumber: 1 cluster: controlPlaneServiceTemplate: spec: type: LoadBalancer controlPlane: dnsConfig: nameservers: - 8.8.8.8 cpu: model: host-passthrough worker: dnsConfig: nameservers: - 8.8.8.8 cpu: model: host-passthroughApply the YAML to your management cluster:
kubectl apply -f my-kubevirt-cluster-deployment.yamlThis starts the provisioning process, where k0rdent creates Cluster API KubeVirt objects in the management cluster and virtual machines in the infrastructure cluster. You can follow the provisioning process with:
kubectl -n kcm-system get clusterdeployment.k0rdent.mirantis.com my-kubevirt-cluster-deployment --watchAfter the cluster is
Ready, you can access it via its kubeconfig, just like any other Kubernetes cluster:kubectl -n kcm-system get secret my-kubevirt-cluster-deployment-kubeconfig -o jsonpath='{.data.value}' | base64 -d > my-kubevirt-cluster-deployment.kubeconfig KUBECONFIG="my-kubevirt-cluster-deployment.kubeconfig" kubectl get pods -A -
Cleanup
To clean up KubeVirt resources, delete the managed cluster by deleting the
ClusterDeployment:kubectl get clusterdeployments -ANAMESPACE NAME READY STATUS kcm-system my-kubevirt-cluster-deployment True Object is readykubectl delete clusterdeployments my-kubevirt-cluster-deployment -n kcm-systemclusterdeployment.k0rdent.mirantis.com "my-kubevirt-cluster-deployment" deleted