加载中...

【Kubernetes】mac 安装minikube

【Kubernetes】mac 安装minikube

New Image

1.一 官网安装

官网: 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

注意点:

xhyve 已经不支持了。提示:darwin 不支持驱动程序“xhyve”
旧文档的brew cask install minikube  不推荐了,
报错:Cask ''minikube'' is unavailable: No Cask with this name exists.   去掉cask直接安装。
  • 1
  • 2
  • 3

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

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

2.安装步骤:

安装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/
或者
(base) lcc@lcc minikube$ brew  install minikube

  • 1
  • 2
  • 3
  • 4

我这里是

(base) lcc@lcc minikube$ brew  install minikube
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/kubernetes-cli-1.18.2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/5f/5f7df7b8226c75aff03a754057cef41150260e3a968d6fc4282738b01b1d8911?__gda__=exp=1589897373~hmac=2c10ee9a4bcc8a1a158bd6168bf094e54653b323056bb0f
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/minikube-1.10.1.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/c0/c0ba6e4c2d00def3af2aa2db3535aef37bb3a7bfe182f35277b3a510b0edffeb?__gda__=exp=1589897433~hmac=29c17a5f940317b89108afbd8dfcde0b0fc3a8b8231e532
######################################################################## 100.0%
==> Installing dependencies for minikube: kubernetes-cli
==> Installing minikube dependency: kubernetes-cli
==> Pouring kubernetes-cli-1.18.2.catalina.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/kubectl
Target /usr/local/bin/kubectl
already exists. You may want to remove it:
  rm ''/usr/local/bin/kubectl''

To force the link and overwrite all conflicting files:
  brew link --overwrite kubernetes-cli

To list all files that would be deleted:
  brew link --overwrite --dry-run kubernetes-cli

Possible conflicting files are:
/usr/local/bin/kubectl -> /Applications/Docker 2.app/Contents/Resources/bin/kubectl
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/kubernetes-cli/1.18.2: 232 files, 49.1MB
==> Installing minikube
==> Pouring minikube-1.10.1.catalina.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/minikube/1.10.1: 8 files, 61.0MB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/lcc/Library/Caches/Homebrew/ccache--3.7.7.catalina.bottle.tar.gz... (91.3KB)
Removing: /Users/lcc/Library/Caches/Homebrew/gettext--0.20.1.catalina.bottle.tar.gz... (8.3MB)
Removing: /Users/lcc/Library/Caches/Homebrew/mercurial--5.3.1.catalina.bottle.tar.gz... (2.5MB)
Removing: /Users/lcc/Library/Caches/Homebrew/openssl@1.1--1.1.1d.catalina.bottle.tar.gz... (5.2MB)
Removing: /Users/lcc/Library/Caches/Homebrew/xz--5.2.4.catalina.bottle.tar.gz... (373.9KB)
Removing: /Users/lcc/Library/Logs/Homebrew/wget... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/libidn2... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/ccache... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/libpng... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/gdbm... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/freetype... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/python... (3 files, 148.7KB)
Removing: /Users/lcc/Library/Logs/Homebrew/libunistring... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/readline... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/sqlite... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/xz... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/gettext... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/mercurial... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/autoconf... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/openssl@1.1... (64B)
Removing: /Users/lcc/Library/Logs/Homebrew/telnet... (64B)
Pruned 0 symbolic links and 5 directories from /usr/local
==> Caveats
==> kubernetes-cli
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> minikube
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
(base) lcc@lcc minikube$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81

这是阿里云版本:

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/
  • 1

输出版本号:

(base) lcc@lcc minikube$ minikube version
minikube version: v1.10.1
commit: 63ab801ac27e5742ae442ce36dff7877dcccb278
(base) lcc@lcc minikube$
  • 1
  • 2
  • 3
  • 4

2.安装 hyperkit

(base) lcc@lcc minikube$ 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
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10.8M  100 10.8M    0     0   154k      0  0:01:12  0:01:12 --:--:--  241k


(base) lcc@lcc ~$ ll /usr/local/bin/ | grep docker-machine-driver-hyperkit
-rwsr-xr-x   1 root  wheel  11428724  5 19 22:25 docker-machine-driver-hyperkit*
(base) lcc@lcc ~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

3. 安装kubectl

安装kubectl

brew install kubectl
  • 1

安装 docker-machine-driver-hyperkit

(base) lcc@lcc bin$ brew install docker-machine-driver-hyperkit
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
closure-compiler                                                docfx                                                           maxwell
==> Updated Casks
master-password                                                 pdfelement                                                      zalo

==> Downloading https://homebrew.bintray.com/bottles/docker-machine-0.16.2.catalina.bottle.tar.gz
Already downloaded: /Users/lcc/Library/Caches/Homebrew/downloads/2743ebd703a6c0755f1bfa98f224c9cc357c9f9d8bcaa8981c798c7a45cfd422--docker-machine-0.16.2.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/docker-machine-driver-hyperkit-1.0.0.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/97/970f9a0f226f1dde7d60e0878a05cef43b503e79f669e2f69fa6e2fd48cfb7f5?__gda__=exp=1589899767~hmac=d124b9b7631e2e6fc82d7aa32deed4b4c80fd321e2ff6c9
######################################################################## 100.0%
==> Installing dependencies for docker-machine-driver-hyperkit: docker-machine
==> Installing docker-machine-driver-hyperkit dependency: docker-machine
==> Pouring docker-machine-0.16.2.catalina.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

To have launchd start docker-machine now and restart at login:
  brew services start docker-machine
Or, if you don''t want/need a background service you can just run:
  docker-machine start
==> Summary
🍺  /usr/local/Cellar/docker-machine/0.16.2: 11 files, 36MB
==> Installing docker-machine-driver-hyperkit
==> Pouring docker-machine-driver-hyperkit-1.0.0.catalina.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/docker-machine-driver-hyperkit
Target /usr/local/bin/docker-machine-driver-hyperkit
already exists. You may want to remove it:
  rm ''/usr/local/bin/docker-machine-driver-hyperkit''

To force the link and overwrite all conflicting files:
  brew link --overwrite docker-machine-driver-hyperkit

To list all files that would be deleted:
  brew link --overwrite --dry-run docker-machine-driver-hyperkit

Possible conflicting files are:
/usr/local/bin/docker-machine-driver-hyperkit
==> Caveats
This driver requires superuser privileges to access the hypervisor. To
enable, execute:
  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
==> Summary
🍺  /usr/local/Cellar/docker-machine-driver-hyperkit/1.0.0: 5 files, 13.7MB
==> Caveats
==> docker-machine
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

To have launchd start docker-machine now and restart at login:
  brew services start docker-machine
Or, if you don''t want/need a background service you can just run:
  docker-machine start
==> docker-machine-driver-hyperkit
This driver requires superuser privileges to access the hypervisor. To
enable, execute:
  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
(base) lcc@lcc bin$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72

输出kubectl --help 信息就OK

4. 启动

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

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

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

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
  • 1

参数对应的含义:

--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
  • 1
  • 2
  • 3
  • 4

这一点没有阿里镜像,我没做下去

😄  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"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

minikube status

host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
  • 1
  • 2
  • 3
  • 4

打开控制台:

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...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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

minikube star
  • 1

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

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

New Image

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