#### **Install Minikube**(centos7)
1. 安装前要求
1. 机器开启虚拟化VT-x or AMD-v。
- linux系统检查是否开启虚拟机化功能
```
egrep "(vmx|svm)" /proc/cpuinfo
```
2. 安装docker (参考前面blog)
```
systemctl status docker
# 如果安装docker启动遇到问题,请注意docker-ce版本
# yum install docker-ce-17.06.1.ce
```
3. 关闭虚拟内存
```
swapoff -a
# 或者注销/etc/fstab 相关行
```
2. 安装 虚拟机管理器Hypervisor (虚拟机形式运行) : virtbox
1. 下载安装VirtualBox
```
wget https://download.virtualbox.org/virtualbox/5.2.22/VirtualBox-5.2-5.2.22_126460_el7-1.x86_64.rpm
rpm -i VirtualBox-5.2-5.2.22_126460_el7-1.x86_64.rpm
# 提示缺少lib插件libSDL-1.2.so.0()(64bit)
# yum install SDL
```
2. 下载安装VirtualBox证书
```
wget https://www.virtualbox.org/download/oracle_vbox.asc
rpm --import oracle_vbox.as
```
3. 安装kubectl
```
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.11.3/bin/linux/amd64/kubectl && chmod +x ./kubectl
&& mv ./kubectl /usr/local/bin/kubectl
```
4. 安装minikube
```
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.31.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube
```
5. 启动minikube前准备
1. 下载相关镜像( 关键点 ,这些镜像都是需要下载到minikube虚拟机中,不是在物理机中,所以很多人还是选择了代理方式安装,或者是阿里云镜像,[Minikube - Kubernetes本地实验环境 ](https://yq.aliyun.com/articles/221687)).
其中,据我分析日志发现,下面是明确需要的镜像:
```
k8s.gcr.io/kube-apiserver-amd64:v1.11.3
k8s.gcr.io/kube-controller-manager-amd64:v1.11.3
k8s.gcr.io/kube-scheduler-amd64:v1.11.3
k8s.gcr.io/kube-proxy-amd64:v1.11.3
k8s.gcr.io/pause:3.1 etcd-amd64:3.2.18
k8s.gcr.io/coredns:1.1.3 kube-addon-manager:v8.6
k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0
gcr.io/k8s-minikube/storage-provisioner:v1.8.1
```
以下的是我参考别人文章自行添加的,以备不时之需:
```
k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8
k8s.gcr.io/8s-dns-dnsmasq-nanny-amd64:1.14.8
k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8
quay.io/coreos/flannel:v0.9.1-amd64
```
我写成了自动安装docker pull images的代码,很抱歉没有写成一个完整的代码。
```
vim imagespull.sh
#!/bin/bash
apilist="kube-apiserver-amd64:v1.11.3 kube-controller-manager-amd64:v1.11.3 kube-scheduler-amd64:v1.11.3 kube-proxy-amd64:v1.11.3 pause:3.1 etcd-amd64:3.2.18 coredns:1.1.3 kube-addon-manager:v8.6 kubernetes-dashboard-amd64:v1.10.0 k8s-dns-sidecar-amd64:1.14.8 k8s-dns-dnsmasq-nanny-amd64:1.14.8 k8s-dns-kube-dns-amd64:1.14.8"
mirror=k8s.gcr.io/
newmirror=anjia0532/google-containers.
for i in $apilist
do
docker pull $newmirror$i
docker tag $newmirror$i $mirror$i
done
chmod +x imagespull.sh
./imagespull.sh
docker pull anjia0532/k8s-minikube.storage-provisioner:v1.8.1
docker tag anjia0532/k8s-minikube.storage-provisioner:v1.8.1 gcr.io/k8s-minikube/storage-provisioner:v1.8.1
docker pull quay.io/coreos/flannel:v0.9.1-amd64
```
6. ##### 启动minikube,很关键一个地方。这个时候需要同时打开两个终端,使用另一个终端进行minikube ssh 操作,如果能连接进minikube虚拟机,切换到第一个终端进行Crtl +Z操作(如果稍晚暂停的话,大概率可能部署失败),然后在minikube虚拟机中(minikube ssh),执行我写的下载镜像的命令,镜像下载完毕之后。切换到第一个终端,执行fg,直至完成。
```
minikube start --kubernetes-version v1.11.3
```
7. 下面是一个报错截图日志截图。显示了缺少gcr镜像文件。可以通过minikube logs查看。
```
E1214 10:47:28.634110 8089 start.go:342] Error starting cluster: kubeadm init error
sudo /usr/bin/kubeadm init --config /var/lib/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests --ignore-preflight-errors=DirAvailable--data-minikube --ignore-preflight-errors=Port-10250 --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-etcd.yaml --ignore-preflight-errors=Swap --ignore-preflight-errors=CRI
running command: : running command:
sudo /usr/bin/kubeadm init --config /var/lib/kubeadm.yaml --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests --ignore-preflight-errors=DirAvailable--data-minikube --ignore-preflight-errors=Port-10250 --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml --ignore-preflight-errors=FileAvailable--etc-kubernetes-manifests-etcd.yaml --ignore-preflight-errors=Swap --ignore-preflight-errors=CRI
, output: [init] using Kubernetes version: v1.11.3
[preflight] running pre-flight checks
[WARNING Swap]: running with swap on is not supported. Please disable swap
I1214 02:45:48.560337 2760 kernel_validator.go:81] Validating kernel version
I1214 02:45:48.560481 2760 kernel_validator.go:96] Validating kernel config
[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 18.06.1-ce. Max validated version: 17.03
[preflight/images] Pulling images required for setting up a Kubernetes cluster
[preflight/images] This might take a minute or two, depending on the speed of your internet connection
[preflight/images] You can also perform this action in beforehand using 'kubeadm config images pull'
[preflight] Some fatal errors occurred:
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-apiserver-amd64:v1.11.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-controller-manager-amd64:v1.11.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-scheduler-amd64:v1.11.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-proxy-amd64:v1.11.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/pause:3.1]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/etcd-amd64:3.2.18]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/coredns:1.1.3]: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
: Process exited with status 2
================================================================================
An error has occurred. Would you like to opt in to sending anonymized crash
information to minikube to help prevent future errors?
To opt out of these messages, run the command:
minikube config set WantReportErrorPrompt false
```
8. 有一些常用命令的命令:
查看kubernetes 相应版本所需镜像
```
kubeadm --kubernetes-version=1.11.0 config images list
```
下载kubernetes 响应版本的镜像(当然需要×××)
```
kubeadm config images pull
```
删除minikube,重新安装
```
minikube delete
rm -rf ~/.minikube
minikube start
```
执行执行minikube ISO (可以在minikube start --help 中的--iso-url 中查看,自己下载到本地)
```
minikube start --iso-url xx
```
本来是想把家里面的破电脑利用起来做rook实验,原以为三两下安装一个minikube没问题,谁曾想安装过程这么坑爹。花了很长时间,但是没关系至少有所收获,对你们也有一定的参考作用。 废话不多说了,继续加油吧。
文章是我使用typora编写的,谁知道直接粘贴到51blog格式出现问题,只能再重新粘贴一份,也可以去我的私人博客上去查看www.vavikast.com
参考链接:
[Minikube - Kubernetes本地实验环境 ](https://yq.aliyun.com/articles/221687)
[kubernets/minikube](https://github.com/kubernetes/minikube)
[Running Kubernetes Locally via Minikube](https://kubernetes.io/docs/setup/minikube/)
[Minikube releases](https://github.com/kubernetes/minikube/releases)
[Install VirtualBox ](https://www.virtualbox.org/wiki/Linux_Downloads)