在CentOS7上采用KVM2驱动安装Minikube

记得之前有段时间在尝试在本机上搭建Minikube学习Kubernetes,即使用阿里制作的minikube,代理翻墙,采用virtualbox驱动方式安装Minikube,折腾了好一段时间, 仍然是无功而返 。那是我刚接触Kubernetes的时候,后来学习Kubernetes完全是抛弃本机部署的尝试,见到minikube 绕着走。

今天又试了一下,在DigitalOcean上部署的,基于CentOS7.6,Minikube vm-driver=kvm2,正好前一段时间做了nomad的libvirt驱动相关工作,对kvm有些理解。minikube实验成功了,整理一下。

主要参考文档


完整流程

(后期根据操作记录整理的,可能有遗漏步骤)
首先DigitalOcean上用来使用minikube的实例,内存>=3G按默认是必要的

# VT-x or AMD-v virtualization must be enabled in your computer’s BIOS. To check this on Linux run the following and verify the output is non-empty:
egrep --color 'vmx|svm' /proc/cpuinfo
# Install a kvm Hypervisor for linux
sudo yum install libvirt-daemon-kvm qemu-kvm
# Enable,start, and verify the libvirtd service has started.
sudo systemctl enable libvirtd.service
sudo systemctl start libvirtd.service
sudo systemctl status libvirtd.service
# Then you will need to add yourself to libvirt group (older distributions may use libvirtd instead)
sudo usermod -a -G libvirt $(whoami)
# Then to join the group with your current user session:
newgrp libvirt
# Now install the driver:
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \
  && sudo install docker-machine-driver-kvm2 /usr/local/bin/
# Install kubectl
# Download the latest release with the command:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
# Make the kubectl binary executable.
chmod +x ./kubectl
# Move the binary in to your PATH.
sudo mv ./kubectl /usr/local/bin/kubectl
# Install Minikube
# You can install Minikube on Linux by downloading a static binary:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
  && chmod +x minikube
# Here’s an easy way to add the Minikube executable to your path:
sudo cp minikube /usr/local/bin && rm minikube
# To use the kvm2 driver:
minikube start --vm-driver kvm2
# or, to use kvm2 as a default driver:
minikube config set vm-driver kvm2
# and run minikube as usual:
minikube start

正确的情况:

[root@centos-1]~# minikube start --vm-driver=kvm2
o   minikube v1.0.1 on linux (amd64)
$   Downloading Kubernetes v1.14.1 images in the background ...
>   Creating kvm2 VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
-   "minikube" IP address is 192.168.39.180
-   Configuring Docker as the container runtime ...
-   Version of container runtime is 18.06.3-ce
:   Waiting for image downloads to complete ...
-   Preparing Kubernetes environment ...
@   Downloading kubelet v1.14.1
@   Downloading kubeadm v1.14.1
-   Pulling images required by Kubernetes v1.14.1 ...
-   Launching Kubernetes v1.14.1 using kubeadm ...
:   Waiting for pods: apiserver proxy etcd scheduler controller dns
-   Configuring cluster permissions ...
-   Verifying component health .....
+   kubectl is now configured to use "minikube"
=   Done! Thank you for using minikube!

可能遇到的问题

  1. 默认使用virtualbox驱动,没安装/指定虚拟机驱动。本文例子中使用的kvm2驱动,也是官方推荐的。
[root@centos-1]~# minikube start
o   minikube v1.0.1 on linux (amd64)
@   Downloading Minikube ISO ...
 142.88 MB / 142.88 MB [============================================] 100.00% 0s
$   Downloading Kubernetes v1.14.1 images in the background ...
>   Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
!   Unable to start VM
X   Error:         [VBOX_NOT_FOUND] create: precreate: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
i   Advice:        Install VirtualBox, ensure that VBoxManage is executable and in path, or select an alternative value for --vm-driver
-   Documentation: https://www.virtualbox.org/wiki/Downloads
-   Related issues:
    - https://github.com/kubernetes/minikube/issues/3784
    - https://github.com/kubernetes/minikube/issues/3776
*   If the above advice does not help, please let us know:
-   https://github.com/kubernetes/minikube/issues/new
  1. kvm2: qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory 内存不够,默认启动的minikube虚拟机需要2G物理内存分配
  1. 之前的启动失败需要删掉vm,重来一遍
[root@centos-1]~# minikube start
o   minikube v1.0.1 on linux (amd64)
$   Downloading Kubernetes v1.14.1 images in the background ...
!   Ignoring --vm-driver=virtualbox, as the existing "minikube" VM was created using the kvm2 driver.
!   To switch drivers, you may create a new VM using `minikube start -p <name> --vm-driver=virtualbox`
!   Alternatively, you may delete the existing VM using `minikube delete -p minikube`
:   Restarting existing kvm2 VM for "minikube" ...
!   Unable to start VM: start: Machine didn't return an IP after 120 seconds
*   Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
-   https://github.com/kubernetes/minikube/issues/new
[root@centos-1]~# grep "^Mem" /proc/meminfo
MemTotal:        2914524 kB
MemFree:           73256 kB
MemAvailable:    1656512 kB
[root@centos-1]~# Unable to start VM: start: Machine didn't return an IP after 120 seconds
[root@centos-1]~# minikube delete -p minikube
x   Deleting "minikube" from kvm2 ...
-   The "minikube" cluster has been deleted.
[root@centos-1]~# minikube start --vm-driver=kvm2

发布者

jahentao

挖掘概念,创造工具