{"id":882,"date":"2019-12-24T16:58:21","date_gmt":"2019-12-24T15:58:21","guid":{"rendered":"https:\/\/blog.unetresgrossebite.com\/?p=882"},"modified":"2019-12-24T17:06:57","modified_gmt":"2019-12-24T16:06:57","slug":"kubevirt","status":"publish","type":"post","link":"https:\/\/blog.unetresgrossebite.com\/?p=882","title":{"rendered":"KubeVirt"},"content":{"rendered":"<p>Today we&#8217;ll take a quick look at KubeVirt, A Kubernetes native virtualization solution.<\/p>\n<p>While OpenShift and Kubernetes have been all about containers, as of 2018, we&#8217;ve started hearing about some weird idea: shipping virtual machines into containers.<\/p>\n<p>Today, KubeVirt is fairly well integrated into OpenShift, which has its own Operator.<\/p>\n<p>If like me, you&#8217;re running OpenShift on KVM guests, you&#8217;ll first have to make sure nested virtualization was enabled. With an Intel processor, we would look for the following:<\/p>\n<p><code>$ cat \/sys\/module\/kvm_intel\/parameters\/nested<br \/>\nY<\/code><\/p>\n<p>Or using AMD:<\/p>\n<p><code>$ cat \/sys\/module\/kvm_amd\/parameters\/nested<br \/>\nY<\/code><\/p>\n<p>Unless the above returns with `Y` or `1`, we need to enable nested<br \/>\nvirtualization. First, shut down all guests. Then, reload your KVM module:<\/p>\n<p><code># modprobe -r kvm_intel<br \/>\n# modprobe kvm_intel nested=1<br \/>\n# cat \/sys\/module\/kvm_intel\/parameters\/nested<br \/>\n# cat &lt;<eof>\/etc\/modprobe.d\/kvm.conf<br \/>\noptions kvm_intel nested=1<br \/>\nEOF<\/eof><\/code><\/p>\n<p>With AMD, use instead:<\/p>\n<p><code># modprobe -r kvm_amd<br \/>\n# modprobe kvm_amd nested=1<br \/>\n# cat \/sys\/module\/kvm_amd\/parameters\/nested<br \/>\n# cat &lt;<eof>\/etc\/modprobe.d\/kvm.conf<br \/>\noptions kvm_amd nested=1<br \/>\nEOF<\/eof><\/code><\/p>\n<p>Reboot your guests, and confirm you can now find a `\/dev\/kvm` device:<\/p>\n<p><code>$ ssh core@compute1.friends<br \/>\nRed Hat Enterprise Linux CoreOS 42.81.20191113.0<br \/>\n...<br \/>\n$ grep vmx \/proc\/cpuinfo<br \/>\nflags\t\t: xxx<br \/>\n...<br \/>\n$ ls \/dev\/kvm<br \/>\n\/dev\/kvm<\/code><\/p>\n<p>Confirm OpenShift node-capability-detector did discover those devices:<\/p>\n<p><code>$ oc describe node compute1.xxx<br \/>\n...<br \/>\nAllocatable:<br \/>\ncpu:                            7500m<br \/>\ndevices.kubevirt.io\/kvm:        110<br \/>\ndevices.kubevirt.io\/tun:        110<br \/>\ndevices.kubevirt.io\/vhost-net:  110<br \/>\n<\/code><\/p>\n<p>Now, from the OperatorHub console, we would install the KubeVirt operator. While writing these lines, there are still some bugs, prefer using some lab cluster doing so.<\/p>\n<p>Next, we&#8217;ll migrate a test KVM instance, from a regular hypervisor to OpenShift. Here, the first thing we would want to do is to provision a DataVolume.<\/p>\n<p>DataVolumes are built on top of PersistentVolumeClaims, they&#8217;re meant to help dealing with persistent volumes, implementing data provisioning.<\/p>\n<p>There&#8217;s two ways to go about this: either we can host our disks using a web server, and then we may use the following DataVolume definition:<\/p>\n<p><code>apiVersion: cdi.kubevirt.io\/v1alpha1<br \/>\nkind: DataVolume<br \/>\nmetadata:<br \/>\n&nbsp;&nbsp;name: bluemind-demo<br \/>\n&nbsp;&nbsp;namespace: wsweet-demo<br \/>\nspec:<br \/>\n&nbsp;&nbsp;source:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;http:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: https:\/\/repository.undomaine.com\/modeles\/kvm\/kvm-kubevirt\/bm40.qcow2<br \/>\n&nbsp;&nbsp;pvc:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;accessModes:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;- ReadWriteOnce<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;resources:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requests:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storage: 20Gi<\/code><\/p>\n<p>Or we could use the virtctl client uploading an image from our system into OpenShift:<\/p>\n<p><code>$ virtctl image-upload dv bluemind-demo --wait-secs=600 --size=8Gi --insecure --block-volume --image-path=\/var\/lib\/libvirt\/images\/bm40-template.raw<br \/>\nDataVolume wsweet-demo\/bluemind-demo created<br \/>\nWaiting for PVC bluemind-demo upload pod to be ready...<br \/>\nPod now ready<br \/>\nUploading data to https:\/\/cdi-uploadproxy-openshift-operators.apps.undomaine.com<br \/>\n...<\/code><\/p>\n<p>The process of uploading a volume would start some temporary Pod, which would use a pair of PVC: one that would receive the final image, the other serving as a temporary storage while upload is running.<\/p>\n<p>Once our image was uploaded, we would be able to create a VirtualMachine object:<\/p>\n<p><code><code>apiVersion: kubevirt.io\/v1alpha3<br \/>\nkind: VirtualMachine<br \/>\nmetadata:<br \/>\n&nbsp;&nbsp;name: bluemind-demo<br \/>\n&nbsp;&nbsp;namespace: wsweet-demo<br \/>\nspec:<br \/>\n&nbsp;&nbsp;running: false<br \/>\n&nbsp;&nbsp;template:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;metadata:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;labels:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: bluemind-demo<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;spec:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domain:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;devices:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disks:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- disk:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bus: virtio<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: rootfs<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;interfaces:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: default<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;masquerade: {}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resources:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requests:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: 8Gi<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpu: \"1\"<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;networks:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: default<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pod: {}<br \/>\nterminationGracePeriodSeconds: 600<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;volumes:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- dataVolume:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: bluemind-demo<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: rootfs<\/code><\/code><\/p>\n<p><code>$ oc get vm<br \/>\n...<br \/>\nbluemind-demo   2s   false<br \/>\n$ virtctl start bluemind-demo<br \/>\n$ oc describe vm bluemind-demo<br \/>\n...<br \/>\n$ oc get vmi<br \/>\n...<br \/>\nbluemind-demo   3s    Scheduling<br \/>\n$ oc get pods<br \/>\n...<br \/>\nvirt-launcher-bluemind-demo-8kcxz   0\/1     ContainerCreating   0   38s<br \/>\n<\/code><\/p>\n<p>Once that Pod is running, we should be able to attach our guest VNC console:<\/p>\n<p><code>$ virtctl vnc bluemind-demo<\/code><\/p>\n<p>Finish up configuring your system, you may have to rename your network<br \/>\ninterfaces, reset IP addresses, fix DNS resolution integrating with OpenShift. Here, we could use cloud-init, or script our own contextualization, installing OpenShift Service CA, &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;ll take a quick look at KubeVirt, A Kubernetes native virtualization solution. While OpenShift and Kubernetes have been all about containers, as of 2018, we&#8217;ve started hearing about some weird idea: shipping virtual machines into containers. Today, KubeVirt is fairly well integrated into OpenShift, which has its own Operator. If like me, you&#8217;re running [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,13,4,2],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/882"}],"collection":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=882"}],"version-history":[{"count":7,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":889,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/882\/revisions\/889"}],"wp:attachment":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}