mac使用minikube搭建k8s图解

本文主要介绍在mac中安装minikube,使用minikube启动k8s

1.首先保证你的电脑BIOS开启了VT-x或者AMD-v虚拟化支持

2.安装Virtual Box(安装这里需要app store授权如下图示)

brew cask install virtualbox
image.png

image.png

授权后再次输入root密码
安装virtualbox成功:


image.png

3.安装kubectl

安装kubectl遇到以下问题 直接执行sudo -i 使用root权限安装即可


image.png
brew install kubectl
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2018-01-26T19:04:38Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}

4.安装minikube

在这里使用的是最新发布版本0.25.0,下载好之后,加入到path下

> wget https://storage.googleapis.com/minikube/releases/v0.25.0/minikube-darwin-amd64
> mv minikube-darwin-amd64 /usr/local/bin/minikube
> chmod +x /usr/local/bin/minikube
minikube version: v0.25.0

5.启动

minikube start
5.1 如果正常的话,到这里已经安装成功了,可惜。。
5.2 出现的第一个错误,是提示minikube-v0.23.6.iso和localkube-v1.8.0这个文件无法下载,猜测是被墙的原因,这里的解决方式是

wget https://storage.googleapis.com/minikube/releases/v0.25.0/minikube-darwin-amd64

wget https://storage.googleapis.com/minikube/iso/minikube-v0.23.6.iso
> mv ~/Downloads/minikube-v0.23.6.iso ~/.minikube/cache/iso
> wget https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64
>  mv ~/Downloads/localkube-linux-amd64 .minikube/cache/localkube/localkube-v1.8.0

再重新执行启动没有报错了,输出如下

> minikube start
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.

5.3 运行hello-minikube

> kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
deployment "hello-minikube" created
> kubectl get pod                                                                                                            
NAME                              READY     STATUS              RESTARTS   AGE
hello-minikube-7844bdb9c6-zwcnr   0/1       ContainerCreating   0          0s

貌似看起来一切正常,可惜等了10几分钟状态依然是ContainerCreating,
执行minikube logs看了下日志

Jul 30 05:34:32 minikube localkube[3244]: I0730 05:34:32.025725    3244 kuberuntime_manager.go:758] checking backoff for container "hello-minikube" in pod "hello-minikube-c6c6764d-wz52t_default(8e5029a3-b282-11e9-ad73-0800273a3ed1)"
Jul 30 05:34:32 minikube localkube[3244]: E0730 05:34:32.027226    3244 pod_workers.go:186] Error syncing pod 8e5029a3-b282-11e9-ad73-0800273a3ed1 ("hello-minikube-c6c6764d-wz52t_default(8e5029a3-b282-11e9-ad73-0800273a3ed1)"), skipping: failed to "StartContainer" for "hello-minikube" with ImagePullBackOff: "Back-off pulling image \"k8s.gcr.io/echoserver:1.4\""
Jul 30 05:34:34 minikube localkube[3244]: E0730 05:34:34.132826    3244 healthcheck.go:317] Failed to start node healthz on 0: listen tcp: address 0: missing port in address

大概的意思就是无法下载image k8s.gcr.io/echoserver:1.4,肯定也是墙的问题

我这里的解决方法是从自己的美国服务器同步镜像到本地然后替换deployment中的镜像文件

kubectl get deployment
NAME             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-minikube   1         1         1            1           1d
wangluludeMacBook-Pro% kubectl edit deployment hello-minikube
Edit cancelled, no changes made.

打开k8s UI管理界面

minikube dashboard
image.png
image.png

你可能感兴趣的:(mac使用minikube搭建k8s图解)