1. kvm2 驱动

KVM(基于内核的虚拟机)是一个基于 x86 硬件的 Linux 的全虚拟化解决方案,包含虚拟化扩展。

要使用 KVM, minikube 依赖 libvirt 虚拟化 API

1.1. 依赖要求

  • libvirt v1.3.1 或更高版本
  • qemu-kvm v2.0 或更高版本

1.2. 安装前准备ß

KVM 和 libvirt 的正确安装对于每个 Linux 发行版来说都是高度特定的。请分别查看:

配置完成后,验证 libvirt 是否报告错误:

virt-host-validate

1.3. 使用

使用 kvm2 驱动启动集群:

minikube start --driver=kvm2

将 kvm2 设置为默认的驱动:

minikube config set driver kvm2

1.4. 确认虚拟化支持

要使用 VM 驱动,请确认您的系统已启用虚拟化支持:

egrep -q 'vmx|svm' /proc/cpuinfo && echo yes || echo no

如果上述命令输出结果是 "no":

  • 如果您在 VM 中运行,那么您的虚拟化管理不允许嵌套虚拟化。您将需要使用 None(裸金属) 驱动(或 docker驱动).
  • 如果您在物理机器上运行,请确保您的 BIOS 启用了硬件虚拟化

1.5. 特性

minikube start 命令支持5个额外的 KVM 特定标志:

  • --gpu: 在 minikube 中启用实验性的 NVIDIA GPU 支持。
  • --hidden: 在 minikube 中向 guest 隐藏虚拟化管理程序签名。
  • --kvm-network: KVM默认的网络名称
  • --network: KVM专用的私有网络名称
  • --kvm-qemu-uri: VM的 qemu uri 默认为 qemu:///system

1.6. 已知问题

  • 如果用户不在正确的 libvirt 组中,minikube 会反复要求输入 root 密码 #3467
  • Machine didn't return an IP after 120 seconds :当防火墙阻止虚拟机网络访问时 #3566
  • unable to set user and group to '65534:992' :当 dynamic ownership = 1 配置 qemu.conf #4467
  • KVM 虚拟机不能与 VirtualBox 同时使用 #4913
  • 在某些发行版上,libvirt 网桥网络可能会失败,需要 reboot 重启机器。

其他问题查看 co/kvm2 open issues

1.6.1. 虚拟化嵌套

如果您在嵌套虚拟化环境中运行 KVM,请确保您的配置内核模块正确地遵循thisthis教程。

1.7. Troubleshooting

  • Run id to confirm that user belongs to the libvirt[d] group (the output should contain entry similar to: 'groups=...,108(libvirt),...').
  • Run virsh domcapabilities --virttype="kvm" to confirm that the host supports KVM virtualisation.
  • Run virt-host-validate and check for the suggestions.
  • Run ls -la `which virsh` , virsh uri, sudo virsh net-list --all and ip a s to collect additional information for debugging.
  • Run minikube start --alsologtostderr -v=9 to debug crashes.
  • Run docker-machine-driver-kvm2 version to verify the kvm2 driver executes properly.
  • Read How to debug Virtualization problems

1.7.1. Troubleshooting KVM/libvirt networks

在大多数情况下,minikube 将尝试为您检测和解决KVM/libvirt网络的任何问题。

但是,在某些情况下需要手动干预,主要是因为需要 root 特权。

1、 运行 sudo virsh net-list --all 列出所有网络接口

例如:

 Name                     State    Autostart   Persistent
-----------------------------------------------------------
 default                  active   yes         yes
 mk-kvm0                  active   yes         yes
 mk-minikube              active   yes         yes
 my-custom-kvm-priv-net   active   yes         yes

解释:

  • default 是默认的 libvirt 网络
  • mk-kvm0 是 minikube 为 kvm0 配置创建的一个的 libvirt 网络 (例如,使用 minikube start -p kvm0 --driver=kvm2),
  • mk-minikube 是 minikube 默认创建的一个 libvirt 网络 (例如,使用 minikube start --driver=kvm2) and
  • my-custom-kvm-priv-net 是一个客户为 minikube 创建的私有网络(例如,使用 minikube start -p kvm1 --driver=kvm2 --network="my-custom-kvm-priv-net").

2、 执行 sudo virsh net-autostart <network> 命令手动将 network 设置为自动启动(如果还没有设置的话)。

3、 执行 sudo virsh net-start <network> 命令手动启动/激活 network (如果尚未启动/active)。

1) 如果默认的 ***default*** libvirt 网络丢失或无法启动/激活-请查阅您的OS/发行版对应的 libvirt 文档;以下步骤可能会帮助您解决此问题:

    - 1.  运行 `sudo virsh net-dumpxml default > default.xml` 来备份 ***default*** 虚拟化网络配置
    - 2.  运行 `sudo virsh net-destroy default` 停止 ***default*** 虚拟化网络.
    - 3.  运行 `sudo virsh net-undefine default` 删除  ***default*** 虚拟化网络.
    - 4.  运行 `sudo virsh net-define /usr/share/libvirt/networks/default.xml` 重新创建 ***default*** 虚拟化网络.
        *  注意: repeat above steps ***b.*** and ***c.*** and then 运行 `sudo virsh net-define default.xml` to restore the original ***default*** libvirt network config, in case of any issue.
    - 5.  运行 `sudo virsh net-start default` 启动  ***default*** 虚拟化网络.
    - 6.  运行 `sudo virsh net-autostart default` 设置开机自动启动 ***default*** 虚拟化网络.

2)  If ***non-default*** libvirt **network** is unable to start/activate, use the following steps:

    - 1.  运行 `sudo virsh net-dumpxml <network>` to dump XML **network** config - note the `bridge name=<bridge>` and `ip address='<address>' netmask='<netmask>'` values. Example output:

    ```xml
    <network connections='1'>
      <name>mk-minikube</name>
      <uuid>cfcb37fb-fd75-4599-825a-14bee5d863f5</uuid>
      <bridge name='virbr1' stp='on' delay='0'/>
      <mac address='52:54:00:80:97:5a'/>
      <dns enable='no'/>
      <ip address='192.168.39.1' netmask='255.255.255.0'>
        <dhcp>
          <range start='192.168.39.2' end='192.168.39.254'/>
        </dhcp>
      </ip>
    </network>
    ```

    - b.  运行 `ip -4 -br -o a s` to show all interfaces with assigned IPs (in CIDR format), now compare the above IP **address** and **netmask** with those of the **bridge**. Example output:

    ```shell
    lo               UNKNOWN        127.0.0.1/8
    virbr0           UP             192.168.122.1/24
    wlp113s0         UP             192.168.42.17/24
    br-08ada8d5dfa4  DOWN           172.22.0.1/16
    docker0          DOWN           172.17.0.1/16
    virbr1           UP             192.168.39.1/24
    ```

    *  ***IF THEY MATCH, or THE IP ADDRESS ISN'T LISTED ANYWHERE***: Run `sudo ip link delete <bridge>` followed by `sudo virsh net-start <network>` and  `sudo virsh net-autostart <network>` to let libvirt recreate the **bridge** and [auto]start the **network**.
    *  ***IF THE IP ADDRESS BELONGS TO ANOTHER INTERFACE***: something else occupied the IP **address** creating the conflict, and you'll have to determine what and then choose between the two...

4、 运行 sudo systemctl restart libvirtdsudo systemctl restart libvirt (根据实际系统或发型版本) 来重启 libvirt 服务。

希望现在 libvirt 网络能够正常运行,并且能够再次成功地运行 minikube。

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2022-06-12 22:31:47

results matching ""

    No results matching ""