一、前言
kubevirt可以扩展kubernetes的功能以管理虚拟机,其架构见文章
https://github.com/kubevirt/kubevirt/blob/master/docs/architecture.md
在安装之前需要先做如下准备工作:
安装libvirt和qemu软件包
yum -y install qemu-kvm libvirt virt-install bridge-utils
给k8s node打标签
kubectl label node k8s-01 kubevirt.io=virt-controller
kubectl label node k8s-02 kubevirt.io=virt-controller
kubectl label node k8s-03 kubevirt.io=virt-api
kubectl label node k8s-04 kubevirt.io=virt-api
查看node能力
kubectl get nodes -o yaml
allocatable:
cpu: "2"
devices.kubevirt.io/tun: "110"
ephemeral-storage: "16415037823"
hugepages-2Mi: "0"
memory: 1780264Ki
pods: "110"
capacity:
cpu: "2"
devices.kubevirt.io/tun: "110"
ephemeral-storage: 17394Mi
hugepages-2Mi: "0"
memory: 1882664Ki
pods: "110"
查看节点是否支持kvm硬件辅助虚拟化
ls /dev/kvm
ls: cannot access /dev/kvm: No such file or directory
virt-host-validate qemu
QEMU: Checking for hardware virtualization : FAIL (Only emulated CPUs are available, performance will be significantly limited)
QEMU: Checking if device /dev/vhost-net exists : PASS
QEMU: Checking if device /dev/net/tun exists : PASS
QEMU: Checking for cgroup 'memory' controller support : PASS
QEMU: Checking for cgroup 'memory' controller mount-point : PASS
QEMU: Checking for cgroup 'cpu' controller support : PASS
QEMU: Checking for cgroup 'cpu' controller mount-point : PASS
QEMU: Checking for cgroup 'cpuacct' controller support : PASS
QEMU: Checking for cgroup 'cpuacct' controller mount-point : PASS
QEMU: Checking for cgroup 'cpuset' controller support : PASS
QEMU: Checking for cgroup 'cpuset' controller mount-point : PASS
QEMU: Checking for cgroup 'devices' controller support : PASS
QEMU: Checking for cgroup 'devices' controller mount-point : PASS
QEMU: Checking for cgroup 'blkio' controller support : PASS
QEMU: Checking for cgroup 'blkio' controller mount-point : PASS
WARN (Unknown if this platform has IOMMU support)
如不支持,则先生成让kubevirt使用软件虚拟化的配置
kubectl configmap -n kube-system kubevirt-config --from-literal debug.useEmulation=true
支持虚拟化的结果如下:
kubectl get nodes -o yaml
allocatable:
cpu: "48"
devices.kubevirt.io/kvm: "110"
devices.kubevirt.io/tun: "110"
ephemeral-storage: "48294789041"
hugepages-1Gi: "0"
hugepages-2Mi: "0"
memory: 263753532Ki
pods: "110"
capacity:
cpu: "48"
devices.kubevirt.io/kvm: "110"
devices.kubevirt.io/tun: "110"
ephemeral-storage: 51175Mi
hugepages-1Gi: "0"
hugepages-2Mi: "0"
memory: 263855932Ki
pods: "110"
转载自https://blog.csdn.net/cloudvtech
二、安装kubevirt
2.1 部署kubevirt
export VERSION=v0.8.0
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/$VERSION/kubevirt.yaml
2.2 查看部署结果
virt-api-79c6f4d756-2vwqh 0/1 Running 0 9s
virt-controller-559c749968-7lwrl 0/1 Running 0 9s
virt-handler-2grjk 1/1 Running 0 9s
virt-handler-djfbr 1/1 Running 0 9s
virt-handler-r2pls 1/1 Running 0 9s
virt-handler-rb948 1/1 Running 0 9s
2.3 virt-controller logs
level=info timestamp=2018-10-06T14:46:37.788008Z pos=application.go:179 component=virt-controller msg="DataVolume integration disabled"
level=info timestamp=2018-10-06T14:46:37.790568Z pos=application.go:194 component=virt-controller service=http action=listening interface=0.0.0.0 port=8182
level=info timestamp=2018-10-06T14:46:55.398082Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer vmiInformer"
level=info timestamp=2018-10-06T14:46:55.398243Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer kubeVirtPodInformer"
level=info timestamp=2018-10-06T14:46:55.398271Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer vmiPresetInformer"
level=info timestamp=2018-10-06T14:46:55.398300Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer vmInformer"
level=info timestamp=2018-10-06T14:46:55.398322Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer limitrangeInformer"
level=info timestamp=2018-10-06T14:46:55.398339Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer kubeVirtNodeInformer"
level=info timestamp=2018-10-06T14:46:55.398359Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer vmirsInformer"
level=info timestamp=2018-10-06T14:46:55.398372Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer configMapInformer"
level=info timestamp=2018-10-06T14:46:55.398385Z pos=virtinformers.go:117 component=virt-controller service=http msg="STARTING informer fakeDataVolumeInformer"
level=info timestamp=2018-10-06T14:46:55.398430Z pos=vm.go:113 component=virt-controller service=http msg="Starting VirtualMachine controller."
level=info timestamp=2018-10-06T14:46:55.399309Z pos=node.go:104 component=virt-controller service=http msg="Starting node controller."
level=info timestamp=2018-10-06T14:46:55.399360Z pos=vmi.go:165 component=virt-controller service=http msg="Starting vmi controller."
level=info timestamp=2018-10-06T14:46:55.399393Z pos=replicaset.go:111 component=virt-controller service=http msg="Starting VirtualMachineInstanceReplicaSet controller."
level=info timestamp=2018-10-06T14:46:55.399416Z pos=preset.go:74 component=virt-controller service=http msg="Starting Virtual Machine Initializer.”
2.4 virt-api logs
level=info timestamp=2018-10-06T14:46:49.538030Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url=/ proto=HTTP/2.0 statusCode=404 contentLength=19
level=info timestamp=2018-10-06T14:46:49.550993Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url=/ proto=HTTP/2.0 statusCode=404 contentLength=19
level=info timestamp=2018-10-06T14:46:51.623461Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url="/apis/subresources.kubevirt.io/v1alpha2?timeout=32s" proto=HTTP/2.0 statusCode=200 contentLength=136
level=info timestamp=2018-10-06T14:46:52.758037Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url=/ proto=HTTP/2.0 statusCode=404 contentLength=19
level=info timestamp=2018-10-06T14:46:52.975272Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url=/openapi/v2 proto=HTTP/2.0 statusCode=404 contentLength=19
level=info timestamp=2018-10-06T14:46:52.976837Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET url=/swagger.json proto=HTTP/2.0 statusCode=404 contentLength=19
level=info timestamp=2018-10-06T14:46:55.124209Z pos=filter.go:46 component=virt-api remoteAddress=10.244.11.128 username=- method=GET