一 官网安装

 官网: https://minikube.sigs.k8s.io/

搜了下网上如何通过Mac 安装看网上文章很多,但是受限于国内网络环境,很多都不行,各种下载失败。如果你有VPN,那么官方的步骤就容易走通:

$ brew install kubectl    
$ brew install minikube     
$ brew install docker-machine-driver-hyperkit
$ sudo chown root:wheel /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
$ sudo chmod u+s /usr/local/opt/docker-machine-driver-hyperkit/bin/docker-machine-driver-hyperkit
$ minikube start --vm-driver hyperkit

注意点:

  • xhyve 已经不支持了。提示:darwin 不支持驱动程序“xhyve”
  • 旧文档的brew cask install minikube  不推荐了,

    报错:Cask 'minikube' is unavailable: No Cask with this name exists.   去掉cask直接安装。

brew 本质是也是一整拉取Git的方式,所以还是想用不适用proxy的情况下如何安装k8s.

我们需要安装三样东西:Kubernetes 的命令行客户端 kubctl、一个可以在本地跑起来的 Kubernetes 环境 Minikube、以及给 Minikube 使用的虚拟化引擎hyperkit.

二  安装步骤:

  

安装minikube

curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/v1.6.2/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
这是阿里云版本:
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.30.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

输出版本号:minikube version

minikube version: v1.6.2
commit: 54f28ac5d3a815d1196cd5d57d707439ee4bb392

安装 hyperkit

curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-hyperkit \
&& chmod +x docker-machine-driver-hyperkit \
&& sudo mv docker-machine-driver-hyperkit /usr/local/bin/ \
&& sudo chown root:wheel /usr/local/bin/docker-machine-driver-hyperkit \
&& sudo chmod u+s /usr/local/bin/docker-machine-driver-hyperkit

 安装kubectl

brew install kubectl
brew install docker-machine-driver-hyperkit

输出kubectl --help 信息就OK

三 启动

   这个也很关键,网上默认的启动报错:

Darwin 10.14.6 上的 minikube v1.6.2

  Selecting 'hyperkit' driver from user configuration (alternates: [])

  正在下载驱动 docker-machine-driver-hyperkit:

    > docker-machine-driver-hyperkit.sha256: 65 B / 65 B [---] 100.00% ? p/s 0s

    > docker-machine-driver-hyperkit: 628.54 KiB / 10.81 MiB  5.68% 1.71 KiB p/

  Unable to update hyperkit driver: download failed: https://github.com/kubernetes/minikube/releases/download/v1.6.2/docker-machine-driver-hyperkit?checksum=file:https://github.com/kubernetes/minikube/releases/download/v1.6.2/docker-machine-driver-hyperkit.sha256: read tcp 192.168.16.30:58130->52.216.142.4:443: read: connection reset by peer

  正在创建 hyperkit 虚拟机(CPUs=2,Memory=2000MB, Disk=20000MB)...

panic: runtime error: invalid memory address or nil pointer dereference

[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x4ecd70f]

 

goroutine 150 [running]:

github.com/google/go-containerregistry/pkg/v1/tarball.Write(0x0, 0xc0006b2780, 0xa, 0xc0006b278b, 0xe, 0xc0006b279a, 0x7, 0x0, 0x0, 0xc000871c68, ...)

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/github.com/google/go-containerregistry@v0.0.0-20180731221751-697ee0b3d46e/pkg/v1/tarball/write.go:57 +0x12f

k8s.io/minikube/pkg/minikube/machine.CacheImage(0xc0006b2780, 0x21, 0xc0006f59f0, 0x45, 0x0, 0x0)

 /private/tmp/minikube-20191220-77113-wmp8w9/pkg/minikube/machine/cache_images.go:395 +0x5df

k8s.io/minikube/pkg/minikube/machine.CacheImages.func1(0xc000028f68, 0x0)

 /private/tmp/minikube-20191220-77113-wmp8w9/pkg/minikube/machine/cache_images.go:85 +0x124

golang.org/x/sync/errgroup.(*Group).Go.func1(0xc000728fc0, 0xc000729020)

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/golang.org/x/sync@v0.0.0-20190423024810-112230192c58/errgroup/errgroup.go:57 +0x64

created by golang.org/x/sync/errgroup.(*Group).Go

 /private/tmp/minikube-20191220-77113-wmp8w9/.brew_home/go/pkg/mod/golang.org/x/sync@v0.0.0-20190423024810-112230192c58/errgroup/errgroup.go:54 +0x66

这里需要在阿里云有账户,开通镜像加速。

minikube start --image-mirror-country=cn   --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.2.iso  --registry-mirror=https://XXXX.mirror.aliyuncs.com  --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

参数对应的含义:

  • --image-mirror-country cn 将缺省利用 registry.cn-hangzhou.aliyuncs.com/google_containers 作为安装Kubernetes的容器镜像仓库,
  • --iso-url=*** 利用阿里云的镜像地址下载相应的 .iso 文件
  • --registry-mirror= 就是你在阿里云的镜像加速地址,必须的,不然很慢。
  • --image-repository=  不选择会提示VM is unable to access k8s.gcr.io, you may need to configure a proxy or set --image-repository

😄  Darwin 10.14.6 上的 minikube v1.6.2
✨  Selecting 'hyperkit' driver from existing profile (alternates: [])
✅  正在使用映像存储库 registry.cn-hangzhou.aliyuncs.com/google_containers
💿  正在下载 VM boot image...

💣  缓存ISO 时失败: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.2.iso: bad response code: 404

😿  minikube is exiting due to an error. If the above message is not useful, open an issue:
👉  https://github.com/kubernetes/minikube/issues/new/choose
benmuMacBook-Pro:Homebrew benmu$ minikube start --image-mirror-country=cn   --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.6.0.iso  --registry-mirror=https://7icj7z92.mirror.aliyuncs.com  --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
😄  Darwin 10.14.6 上的 minikube v1.6.2
✨  Selecting 'hyperkit' driver from existing profile (alternates: [])
✅  正在使用映像存储库 registry.cn-hangzhou.aliyuncs.com/google_containers
💡  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
🏃  Using the running hyperkit "minikube" VM ...
⌛  Waiting for the host to be provisioned ...
🐳  正在 Docker '19.03.5' 中准备 Kubernetes v1.17.0…
E0117 16:48:18.733289   68071 cache_images.go:86] CacheImage registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 -> /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0 failed: write: UNAUTHORIZED: "authentication required"
E0117 16:48:18.736915   68071 start.go:839] Error caching images:  Caching images for kubeadm: caching images: caching image /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0: write: UNAUTHORIZED: "authentication required"
❌  Unable to load cached images: loading cached images: stat /Users/benmu/.minikube/cache/images/registry.cn-hangzhou.aliyuncs.com/google_containers/etcd_3.4.3-0: no such file or directory
🚀  正在启动 Kubernetes ... 
🏄  完成!kubectl 已经配置至 "minikube"

minikube status

host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

打开控制台:

minikube dashboard

🔌  正在开启 dashboard ...
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:49155/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

 

新手记录下自己搭建过程,主要是

minikube star

这里一开始没用对参数,各种报错,然后删除 ~/.minikube 再加上参数重试。

最后,引用下阿里云的图:Minikube利用本地虚拟机环境部署Kubernetes,其基本架构如下图所示。

4

好了,开始你的k8s之旅吧。 

 

参考:

https://yq.aliyun.com/articles/221687

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐