Debian 12 bookworm
Sponsored Link

Kubernetes : Install KubeVirt2024/10/29

 

Install KubeVirt to deploy fully virtualized virtual machines in Kubernetes Cluster.

This example is based on the environment like follows.

-----------+---------------------------+--------------------------+------------
           |                           |                          |
       eth0|10.0.0.25              eth0|10.0.0.71             eth0|10.0.0.72
+----------+-----------+   +-----------+-----------+   +-----------+-----------+
|  [ ctrl.srv.world ]  |   |  [snode01.srv.world]  |   |  [snode02.srv.world]  |
|     Control Plane    |   |      Worker Node      |   |      Worker Node      |
+----------------------+   +-----------------------+   +-----------------------+

[1] Install KubeVirt and virtctl command.
root@ctrl:~#
export VERSION=$(curl https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt)

root@ctrl:~#
wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-operator.yaml

root@ctrl:~#
wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt-cr.yaml

root@ctrl:~#
wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-linux-amd64
root@ctrl:~#
mv virtctl-${VERSION}-linux-amd64 /usr/local/bin/virtctl

root@ctrl:~#
chmod 755 /usr/local/bin/virtctl
root@ctrl:~#
kubectl apply -f kubevirt-operator.yaml

namespace/kubevirt created
customresourcedefinition.apiextensions.k8s.io/kubevirts.kubevirt.io created
priorityclass.scheduling.k8s.io/kubevirt-cluster-critical created
clusterrole.rbac.authorization.k8s.io/kubevirt.io:operator created
serviceaccount/kubevirt-operator created
role.rbac.authorization.k8s.io/kubevirt-operator created
rolebinding.rbac.authorization.k8s.io/kubevirt-operator-rolebinding created
clusterrole.rbac.authorization.k8s.io/kubevirt-operator created
clusterrolebinding.rbac.authorization.k8s.io/kubevirt-operator created
deployment.apps/virt-operator created

root@ctrl:~#
kubectl apply -f kubevirt-cr.yaml

kubevirt.kubevirt.io/kubevirt created
# after a few minutes, the pods will start up as follows

root@ctrl:~#
kubectl get pods -n kubevirt

NAME                               READY   STATUS    RESTARTS   AGE
virt-api-fdbc87c9-n4hzk            1/1     Running   0          2m32s
virt-api-fdbc87c9-pdtlx            1/1     Running   0          2m32s
virt-controller-844699784f-h48jl   1/1     Running   0          2m6s
virt-controller-844699784f-tfjqx   1/1     Running   0          2m6s
virt-handler-9ptpt                 1/1     Running   0          2m6s
virt-handler-pwmt2                 1/1     Running   0          2m6s
virt-operator-74bdf99686-fs77w     1/1     Running   0          3m15s
virt-operator-74bdf99686-ppllh     1/1     Running   0          3m15s
[2] Create a test VM and verify it works normally.
root@ctrl:~#
wget https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml

root@ctrl:~#
kubectl apply -f vm.yaml

virtualmachine.kubevirt.io/testvm created
root@ctrl:~#
kubectl get vms

NAME     AGE   STATUS    READY
testvm   56s   Stopped   False

# start VM

root@ctrl:~#
virtctl start testvm

VM testvm was scheduled to start
root@ctrl:~#
kubectl get vms

NAME     AGE     STATUS    READY
testvm   2m35s   Running   True

root@ctrl:~#
kubectl get vmi

NAME     AGE   PHASE     IP                NODENAME            READY
testvm   89s   Running   192.168.211.132   snode02.srv.world   True

# connect to VM
# user is 'cirros' and password is 'gocubsgo'

root@ctrl:~#
ssh cirros@192.168.211.132

The authenticity of host '192.168.211.132 (192.168.211.132)' can't be established.
ECDSA key fingerprint is SHA256:20H5wmy0Jxe0Sq+WevClymQI9QPilKy2dtSW+85ka2M.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.211.132' (ECDSA) to the list of known hosts.
cirros@192.168.211.132's password:
$ 
$ uname -a
Linux testvm 4.4.0-28-generic #47-Ubuntu SMP Fri Jun 24 10:09:13 UTC 2016 x86_64 GNU/Linux
$ cat /etc/os-release
NAME=Buildroot
VERSION=2015.05-g31af4e3-dirty
ID=buildroot
VERSION_ID=2015.05
PRETTY_NAME="Buildroot 2015.05"
$ exit
Connection to 192.168.211.132 closed.

# connect to the console of VM

root@ctrl:~#
virtctl console testvm

Successfully connected to testvm console. The escape sequence is ^]

login as 'cirros' user. default password: 'gocubsgo'. use 'sudo' for root.
testvm login: cirros
Password:
$ 
# to go back to the Host's console, push Ctrl + ] key
# * same operation as virsh command
root@ctrl:~#

# stop VM

root@ctrl:~#
virtctl stop testvm

VM testvm was scheduled to stop
root@ctrl:~#
kubectl get vms

NAME     AGE     STATUS    READY
testvm   8m41s   Stopped   False

# delete VM

root@ctrl:~#
kubectl delete vm testvm

virtualmachine.kubevirt.io "testvm" deleted
root@ctrl:~#
kubectl get vms

No resources found in default namespace.
Matched Content