本文将从Kubevirt的价值,潜力,安装,架构,特性及如何使用两方面介绍。
如果说kubevirt的价值是什么?那么就是要问为什么需要Kubevirt。
kubevirt 技术试图解决在开发团队已经接受或者试图接受K8S思想时但存在有些基于虚拟化的工作负载难以实现容器化的情景。
更确切地说,KubeVirt提供了一个统一的开发平台,开发者在同一个共享环境中既能够对容器化的应用程序构建,修改,部署,也能对虚拟化的应用程序进行同样的操作。
这样做好处是广泛而显著的。依赖基于虚拟机工作负载的团队有能力迅速容器化应用。随着虚拟化工作负载直接放置在开发工作流程,随着时间的推移,团队仍可以对工作负载进行分解,同时可以无缝地利用其他虚拟化组件。
利用KubeVirt能做哪些事情?
For Intel Processors
# cat /sys/module/kvm_intel/parameters/nested
Y[1]
For AMD Processors
# $ cat /sys/module/kvm_amd/parameters/nested
Y[1]
If Value is not Y[1], do actions as below:
Intel Processor
# modprobe -r kvm_intel
# modprobe kvm_intel nested=1
AMD Processor
# modprobe -r kvm_amd
# modprobe kvm_amd nested=1
If you want to enable it permanently, as below:
Intel Processor
# echo 'options kvm_intel nested=1' >/etc/modprobe.d/kvm-nested.conf
AMD Processor
# echo 'options kvm_amd nested=1' >/etc/modprobe.d/kvm-nested.conf
If CPU supports virtualization extensions, Some messages will be output after executing the following command:
# egrep 'svm|vmx' /proc/cpuinfo
If not, create the ConfigMap so that KubeVirt uses emulation mode:
# kubectl create configmap kubevirt-config -n kubevirt --from-literal debug.useEmulation=true
# KubeVirt's Version
$ export KUBEVIRT_VERSION=v0.23.0
# creates KubeVirt operator
$ kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
# creates KubeVirt KV custom resource
$ kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml
(1) Create Kubevirt Directory and Set Kubevirt version ENV
# mkdir Kubevirt
# pushd Kubevirt
# export KUBEVIRT_VERSION="v0.23.0"
(2) Download KubeVirt VirtCtl and Install
# curl -L -o /usr/local/bin/virtctl https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/virtctl-${KUBEVIRT_VERSION}-linux-amd64
# chmod +x /usr/local/bin/virtctl
# virtctl --help
virtctl controls virtual machine related operations on your kubernetes cluster.
Available Commands:
console Connect to a console of a virtual machine instance.
expose Expose a virtual machine instance, virtual machine, or virtual machine instance replica set as a new service.
help Help about any command
image-upload Upload a VM image to a PersistentVolumeClaim.
restart Restart a virtual machine.
start Start a virtual machine.
stop Stop a virtual machine.
version Print the client and server version information.
vnc Open a vnc connection to a virtual machine instance.
Use "virtctl --help" for more information about a given command.
Use "virtctl options" for a list of global command-line options (applies to all commands).
(3) Download Kubevirt Operator and Custom Resources yaml files
# wget https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml
# wget https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml
(4) Download testVM yaml
# wget https://raw.githubusercontent.com/kubevirt/kubevirt.github.io/master/labs/manifests/vm.yaml
# popd Kubevirt
(5) CDI Deploy
VERSION=v1.10.9
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator.yaml
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator-cr.yaml
(6) Deploy hostpath
mkdir -p /var/run/kubevirt/hostpath
kubectl create -f https://github.com/kubevirt/kubevirt/blob/master/docs/devel/hostpath-provisioner.yaml
# pushd Kubevirt
# kubectl create -f kubevirt-operator.yaml
# kubectl get pods -n kubevirt
NAME READY STATUS RESTARTS AGE
virt-operator-7f589cd8cb-2fsm8 0/1 ContainerCreating 0 12s
...
virt-operator-7f589cd8cb-n9knm 1/1 Running 0 28s
# kubectl create -f kubevirt-cr.yaml
# kubectl get pods -n kubevirt
NAME READY STATUS RESTARTS AGE
virt-api-7dc455b79c-b7l8j 1/1 Running 1 31h
virt-api-7dc455b79c-p8sl5 1/1 Running 1 31h
virt-controller-76cccd9979-kr7sv 1/1 Running 3 31h
virt-controller-76cccd9979-q9cxk 1/1 Running 3 31h
virt-handler-k8df6 1/1 Running 1 31h
virt-operator-7f589cd8cb-2fsm8 1/1 Running 2 2d23h
virt-operator-7f589cd8cb-n9knm 1/1 Running 5 2d23h
then the pod, svc status as below:
# kubectl get po -n kubevirt
NAME READY STATUS RESTARTS AGE
virt-api-7dc455b79c-b7l8j 1/1 Running 0 60m
virt-api-7dc455b79c-p8sl5 1/1 Running 0 60m
virt-controller-76cccd9979-kr7sv 1/1 Running 0 57m
virt-controller-76cccd9979-q9cxk 1/1 Running 0 57m
virt-handler-k8df6 1/1 Running 0 60m
virt-operator-7f589cd8cb-2fsm8 1/1 Running 1 40h
virt-operator-7f589cd8cb-n9knm 1/1 Running 1 40h
# kubectl get svc -n kubevirt
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubevirt-prometheus-metrics ClusterIP 10.96.32.24 <none> 443/TCP 62m
virt-api ClusterIP 10.108.69.243 <none> 443/TCP 62m
# kubectl apply -f vm.yaml
# kubectl get vms
NAME AGE RUNNING VOLUME
testvm 54m false
# kubectl get vms -o yaml testvm
Note:
Field RUNNING is set “false”, that means we’ve only defined the object but it now needs to be instantiated but not be running,
We should start VM with virtctl:
# virtctl start testvm
VM testvm was scheduled to start
# kubectl get vms
NAME AGE RUNNING VOLUME
testvm 59m true
# kubectl get vmis
NAME AGE PHASE IP NODENAME
testvm 25s Running 10.244.166.133 node1
# kubectl get vmis -o yaml testvm
Note:
(1) vmis stands for VirtualMachineInstance.
(2) Field PHASE indicates VMI’s progress transitioning from one state to the next till to RUNNING.
Using virtctl to connect to the VMI consoles interfaces, and EXIT with “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:gocubsgo
$ uname -msr
Linux 4.4.0-28-generic x86_64
$
VNC to Connet to VM, VNC requires remote-viewer from the virt-viewer package installed on the host.
# virtctl vnc testvm
(1) Stop VM
# virtctl stop testvm
VM testvm was scheduled to stop
(2) Delete VM
# kubectl delete vm testvm
virtualmachine.kubevirt.io "testvm" deleted
台球猫头鹰的脚印
kubevirt官网
kubevirt以容器方式运行虚拟机