minikube安装具体过程

时间:2020-8-27 作者:admin

目录

 

一、安装centOS,并配置网络

二、安装docker

三、安装kubectl

 四、安装minikube

 


一、安装centOS,并配置网络

本地安装好虚拟机后,需要查看网卡配置信息:

# cd  /etc/sysconfig/network-scripts/

# cd /etc/sysconfig/network-scripts/
ls -l

找到网卡配置文件 :

编辑该配置文件:

# vi ifcfg-ens33

按如下配置进行设置:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=db6de55c-2f4d-441a-a2ff-025a9aea8898
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.56.14
NETMASK=255.255.255.0
GATEWAY=192.168.56.2
~                                                                                                                      
~ 

重启网络服务:

# systemctl restart network

设置DNS解析:

# vi /etc/resolv.conf
nameserver 192.168.56.2

更新系统并重启:

# yum update -y && reboot

二、安装docker

添加Yum仓库:

# cd /etc/yum.repos.d/
# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

docker安装:

# yum install -y docker-ce

启动后台进程:

# systemctl start docker && systemctl enable docker

查看版本:

# docker --version

有如下返回,则说明安装成功:

Docker version 19.03.12, build 48a66213fe

三、安装kubectl

kubectl是k8s的命令行工具,通过它可以对k8s集群进行操作,一般的安装链接如下,但是不知道什么原因,这个资源经常掉线,下载下来要很长时间:

# curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

个人建议通过如下链接,直接找到相应版本,将中间的v1.7.0替换掉即可:

 https://storage.googleapis.com/kubernetes-release/release/v1.7.0/bin/linux/amd64/kubectl

下载下来后拖拽到centOS的根目录下,赋予执行权限,并移动到bin目录下: 

# chmod +x ./kubectl
# mv ./kubectl /usr/local/bin/kubectl

检查版本:

# kubectl version

Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.0", GitCommit:"d3ada0119e776222f11ec7945e6d860061339aad", GitTreeState:"clean", BuildDate:"2017-06-29T23:15:59Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"

 四、安装minikube

具体可参考这篇文章:

https://developer.aliyun.com/article/221687

但是安装后,执行,切记切记,一定要使用 非root用户启动

$ minikube start

这一句执行时,经常会采坑,最主要的坑

1,虚拟机没有设置 cpu虚拟化,这个在一开始创建虚机的时候就要选上,否则很容易出错,具体设置如下:

 

2,还有一点非常重要,非root用户启动minikube,会遇到如下报错:

$ minikube start

* minikube v1.12.3 on Centos 7.8.2003
* Unable to pick a default driver. Here is what was considered, in preference order:
  - docker: Not healthy: "docker version --format {{.Server.Os}}-{{.Server.Version}}" exit status 1: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denied
  - kvm2: Not installed: exec: "virsh": executable file not found in $PATH
  - none: Not healthy: the 'none' driver must be run as the root user
  - podman: Not installed: exec: "podman": executable file not found in $PATH
  - virtualbox: Not installed: unable to find VBoxManage in $PATH
  - vmware: Not installed: exec: "docker-machine-driver-vmware": executable file not found in $PATH
  - Try specifying a --driver, or see https://minikube.sigs.k8s.io/docs/start/

 注意到有“ Got permission denied”字样,初步怀疑是非root用户没有执行docker的权限,查询后得知,需将用户加入到docker group组中,方可获得执行 docker的权限。

具体原因如下(docker手册)

Manage Docker as a non-root user

The docker daemon binds to a Unix socket instead of a TCP port. By
default that Unix socket is owned by the user root and other users can
only access it using sudo. The docker daemon always runs as the root
user.

If you don’t want to use sudo when you use the docker command, create
a Unix group called docker and add users to it. When the docker daemon
starts, it makes the ownership of the Unix socket read/writable by the
docker group.

根据以上分析,得出解决方案:切回到root用户,修改sudo配置文件 visodu

# visodu

将全部的管理员权限赋予user,当然你也可以通过更精细化的设置来达到最小授权,这样安全性会高一些。

$user ALL=(ALL) ALL

切换回user用户,并将用户添加到docker组中,千万不能直接用:
sudo usermod -G docker
这样做会使你离开其他用户组,仅仅做为这个用户组docker的成员。
应该用 加上 -a 选项:
sudo usermod -a -G docker $user
(FC4: usermod -G groupA,groupB,groupC user)
-a 代表 append, 也就是 将自己添加到用户组docker中,而不必离开其他用户组。
newgrp docker     #更新用户组,生效

此时,执行

$ docker version
Client: Docker Engine - Community
 Version:           19.03.12

返回版本,权限增加成功

再次执行 minikube start

接下来就是紧张的等待了~~

终于:

* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* Creating docker container (CPUs=2, Memory=1819MB) ...
* Preparing Kubernetes v1.18.3 on Docker 19.03.8 ...
    > kubeadm.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubelet.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubectl.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm: 37.97 MiB / 37.97 MiB [---------------] 100.00% 1.19 MiB p/s 32s
    > kubectl: 41.99 MiB / 41.99 MiB [---------------] 100.00% 1.16 MiB p/s 36s
    > kubelet: 108.04 MiB / 108.04 MiB [-----------] 100.00% 1.36 MiB p/s 1m19s
* Verifying Kubernetes components...
! Executing "docker container inspect minikube --format={{.State.Status}}" took an unusually long time: 4.689291201s
* Restarting the docker service may improve performance.
! Executing "docker container inspect minikube --format={{.State.Status}}" took an unusually long time: 4.717134347s
* Restarting the docker service may improve performance.
* Enabled addons: default-storageclass, storage-provisioner
* Done! kubectl is now configured to use "minikube"

两眼泪汪汪了!!成功~~~

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。