CentOS Stream 10: Install KubeVirt
Install KubeVirt to manage virtual machines within a Kubernetes cluster on CentOS Stream 10.
Install KubeVirt to deploy fully virtualized virtual machines in Kubernetes Cluster.
This example is based on the environment like follows.
+----------------------+ +----------------------+
| [ ctrl.srv.world ] | | [ dlp.srv.world ] |
| Manager Node | | Control Plane |
+-----------+----------+ +-----------+----------+
eth0|10.0.0.25 eth0|10.0.0.30
| |
------------+--------------------------+-----------
| |
eth0|10.0.0.51 eth0|10.0.0.52
+-----------+----------+ +-----------+----------+
| [ node01.srv.world ] | | [ node02.srv.world ] |
| Worker Node#1 | | Worker Node#2 |
+----------------------+ +----------------------+
Step 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-79f9fddf79-c6d6g 1/1 Running 0 6m46s
virt-api-79f9fddf79-jkqkc 1/1 Running 0 6m46s
virt-controller-8c5bb5cb7-gsb69 1/1 Running 0 6m11s
virt-controller-8c5bb5cb7-mcn6w 1/1 Running 0 6m11s
virt-handler-gll79 1/1 Running 0 6m11s
virt-handler-wd24v 1/1 Running 0 6m11s
virt-operator-589997bf4b-7tp9g 1/1 Running 0 7m37s
virt-operator-589997bf4b-rf2bh 1/1 Running 0 7m37s
Step 2
Create a test VM and verify it works normally.
[cent@ctrl ~]$ wget https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml
[cent@ctrl ~]$ kubectl apply -f vm.yaml
virtualmachine.kubevirt.io/testvm created
[cent@ctrl ~]$ kubectl get vms
NAME AGE STATUS READY
testvm 4s Stopped False
start VM
[cent@ctrl ~]$ virtctl start testvm
VM testvm was scheduled to start
[cent@ctrl ~]$ kubectl get vms
NAME AGE STATUS READY
testvm 33s Running True
[cent@ctrl ~]$ kubectl get vmi
NAME AGE PHASE IP NODENAME READY
testvm 29s Running 192.168.241.150 node02.srv.world True
connect to the console of VM
[cent@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: <span class="color1">cirros</span>
Password:
$
<span class="color2"># to go back to the Host's console, push Ctrl + ] key
# * same operation as virsh command</span>
connect to VM via ssh
user is 'cirros' and password is 'gocubsgo'
[cent@ctrl ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
virt-launcher-testvm-ctvg9 3/3 Running 0 56s
[cent@ctrl ~]$ kubectl port-forward pod/virt-launcher-testvm-ctvg9 2220:22 &
[cent@ctrl ~]$ ssh cirros@localhost -p 2220
Handling connection for 2220
The authenticity of host '[localhost]:2220 ([::1]:2220)' can't be established.
ECDSA key fingerprint is SHA256:w6n7JIepYQqbXO7Mzf4qxUpCvzAzMEKGCy3Bc9MIMW8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? <span class="color1">yes</span>
Warning: Permanently added '[localhost]:2220' (ECDSA) to the list of known hosts.
cirros@localhost's password:
$
$ <span class="color1">uname -a</span>
Linux testvm 4.4.0-28-generic #47-Ubuntu SMP Fri Jun 24 10:09:13 UTC 2016 x86_64 GNU/Linux
$ <span class="color1">cat /etc/os-release</span>
NAME=Buildroot
VERSION=2015.05-g31af4e3-dirty
ID=buildroot
VERSION_ID=2015.05
PRETTY_NAME="Buildroot 2015.05"
$ <span class="color1">exit</span>
Connection to localhost closed.
stop VM
[cent@ctrl ~]$ virtctl stop testvm
VM testvm was scheduled to stop
[cent@ctrl ~]$ kubectl get vms
NAME AGE STATUS READY
testvm 3m4s Stopped False
delete VM
[cent@ctrl ~]$ kubectl delete vm testvm
virtualmachine.kubevirt.io "testvm" deleted
[cent@ctrl ~]$ kubectl get vms
No resources found in default namespace.