容器服务Docker&Kubernetes 关注
手机版

Minikube - Kubernetes本地实验环境

  1. 云栖社区>
  2. 容器服务Docker&Kubernetes>
  3. 博客>
  4. 正文

Minikube - Kubernetes本地实验环境

易立 2017-10-07 11:13:42 浏览57667 评论42

摘要: 为了方便大家本地开发和体验Kubernetes,社区提供了可以在本机部署的Minikube。本文介绍利用阿里云的镜像地址在Windows/Mac/Linux上来部署和配置Minikube

logo.png

为了方便大家开发和体验Kubernetes,社区提供了可以在本地部署的Minikube。由于网络访问原因,很多朋友无法使用minikube进行实验。为此我们提供了一个修改版的Minikube,可以从阿里云的镜像地址来获取所需Docker镜像和配置。

注:

  • 本文已更新到 Minikube v0.30.0/Kubernetes v1.10+
  • 如需更新minikube,需要更新 minikube 安装包

    • minikube delete 删除现有虚机,删除 ~/.minikube 目录缓存的文件
    • 重新创建 minikube 环境
  • Docker社区版也为Mac/Windows用户提供了Kubernetes开发环境的支持 https://yq.aliyun.com/articles/508460,大家也可以试用

配置

先决条件

Minikube在不同操作系统上支持不同的驱动

  • macOS

  • Linux

    • VirtualBoxKVM
    • NOTE: Minikube 也支持 --vm-driver=none 选项来在本机运行 Kubernetes 组件,这时候需要本机安装了 Docker。在使用 0.27版本之前的 none 驱动时,在执行 minikube delete 命令时,会移除 /data 目录,请注意,问题说明;另外 none 驱动会运行一个不安全的API Server,会导致安全隐患,不建议在个人工作环境安装。
  • Windows

注:

  • 由于minikube复用了docker-machine,在其软件包中已经支持了相应的VirtualBox, VMware Fusion驱动
  • VT-x/AMD-v 虚拟化必须在 BIOS 中开启
  • 在Windows环境下,如果开启了Hyper-V,不支持VirtualBox方式

Kubernetes 1.10+ release

我们提供了最新的Minikube修改版的文件,可以直接下载使用

Mac OSX

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/

Linux

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.30.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Windows

下载 minikube-windows-amd64.exe 文件,并重命名为 minikube.exe

Kubernetes 1.9 release

Mac OSX

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.25.2/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Linux

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.25.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Windows

下载 minikube-windows-amd64.exe 文件,并重命名为 minikube.exe

自己构建

也可以从Github上获取相应的项目自行构建。

注:需要本地已经安装配置好 Golang 开发环境和Docker引擎

git clone https://github.com/AliyunContainerService/minikube
cd minikube
git checkout aliyun-v0.25.0
make
sudo cp out/minikube /usr/local/bin/

启动

缺省Minikube使用VirtualBox驱动来创建Kubernetes本地环境

minikube start --registry-mirror=https://registry.docker-cn.com

支持不同的Kubernetes版本

# 安装Kubernetes v1.12.1
minikube start --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.12.1

# 安装Kubernetes v1.11.3
minikube start --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.11.3

打开Kubernetes控制台

minikube dashboard

image

对于使用Hyper-V环境的用户,首先应该打开Hyper-V管理器创建一个外部虚拟交换机,

create

hyper_v

之后,我们可以用如下命令来创建基于Hyper-V的Kubernetes测试环境

.\minikube.exe start --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="MinikubeSwitch"

注:需要管理员权限来创建Hyper-V虚拟机

使用Minikube

Minikube利用本地虚拟机环境部署Kubernetes,其基本架构如下图所示。
4

用户使用Minikube CLI管理虚拟机上的Kubernetes环境,比如:启动,停止,删除,获取状态等。一旦Minikube虚拟机启动,用户就可以使用熟悉的Kubectl CLI在Kubernetes集群上执行操作。

好了,开始探索Kubernetes的世界吧!:-)

【云栖快讯】阿里云栖开发者沙龙(Java技术专场)火热来袭!快来报名参与吧!  详情请点击

网友评论

1F
1590823026545057

启动minikube的时候还是会去storage.googleapis.com下载文件
Downloading localkube binary
E1109 11:08:11.489207 11931 start.go:222] Error updating cluster: Error updating localkube from uri: Error attempting to download and cache localkube: failed to download: failed to download to temp file: download failed: 5 error(s) occurred:

  • Temporary download error: Get https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64: net/http: TLS handshake timeout
  • Temporary download error: Get https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64: dial tcp 216.58.200.240:443: i/o timeout
  • Temporary download error: Get https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64: dial tcp 216.58.200.240:443: i/o timeout
  • Temporary download error: Get https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64: dial tcp 216.58.200.240:443: i/o timeout
  • Temporary download error: Get https://storage.googleapis.com/minikube/k8sReleases/v1.8.0/localkube-linux-amd64: dial tcp 216.58.200.240:443: i/o timeout

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

================================================================================
Please enter your response [Y/n]:

1086462786678396

我也遇到同样的问题,请问怎么解决的呢

易立

Fixed, thanks for feedback

1984194448313980

@易立 你好,还是有出现这个问题,请问怎么解决呢

1984194448313980

@1984194448313980 已解决 可忽略

1362666300234775

@1984194448313980 兄弟,请问这个问题你是怎么解决的呢?

易立

Fixed, 0.28.1重新下载一下就好

评论
2F
31090765

启动后
C:Userszhaolin>kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system kube-addon-manager-minikube 0/1 ContainerCreating 0 32m

一直在创建容器状态,请问哪里看日志?
手动进入虚拟机pull了也没效果

3F
lrk519

kube-system kube-addon-manager-minikube 0/1 ContainerCreating 0 32m 还在ContainerCreating的原因是这里还有一个pause-amd64镜像地址没有改。解决办法是:

minikube sshdocker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.0docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
易立

Fixed

评论
4F
易立

如果遇到问题,请删除 ~/.minikube 目录,并且重新下载minikube

5F
eumji

http://registry.cn-hangzhou.aliyuncs.com/ 挂了

易立

不能直接访问registry.cn-hangzhou.aliyuncs.com,这是镜像仓库URL

eumji

之前有段时间无法下载镜像,今天试了一下,可以了.感谢

评论
6F
1326004087769549

[root@Ubuntu-001 ~]# minikube start --registry-mirror=https://registry.docker-cn.com
Starting local Kubernetes v1.8.0 cluster...
Starting VM...
E0104 15:59:13.572964 1783 start.go:150] Error starting host: Error creating host: Error executing step: Running precreate checks.
: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory.

Retrying.
E0104 15:59:13.574164 1783 start.go:156] Error starting host: Error creating host: Error executing step: Running precreate checks.
: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory

好像是cpu没有开启虚拟化,但是ubuntu怎么打开这个虚拟化?因为我的ubuntu是装在virtualbox里的,貌似没法进入BIOS设置啊,求助,谢谢!

[root@Ubuntu-001 ~]# egrep -c '(vmx|svm)' /proc/cpuinfo
0
[root@Ubuntu-001 ~]# kvm-ok
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
查询到确实没有开启

易立

minikube 是依赖于Virtualbox的,需要在虚拟机外部运行。 或者使用 sudo -E ./minikube start --vm-driver=none
部署在本机,(我没有测试过期待反馈)

飞浪

mac下提示不支持none类型的driver,只有linux下支持?

飞浪

Starting local Kubernetes v1.10.0 cluster...
Starting VM...
F0630 16:12:17.956053 9500 cluster.go:212] Unsupported driver: none

评论
7F
orican

安装的时候出现了这种问题
image

orican

mac环境下

易立

minikube delete
rm ~/.minikube
再重新试一下

评论
8F
ehlxr

很棒,😆

9F
陈振阳

minikube 0.24.1
ubuntu 16.04环境下,启动日志报如下的错误,楼主遇到过么?

Jan 18 14:14:24 minikube localkube[3185]: E0118 14:14:24.606557 3185 ready.go:40] Error performing healthcheck: Get https://localhost:8443/healthz: dial tcp 127.0.0.1:8443: getsockopt: connection refused
Jan 18 14:14:25 minikube localkube[3185]: I0118 14:14:25.605536 3185 ready.go:30] Performing healthcheck on https://localhost:8443/healthz
Jan 18 14:14:25 minikube localkube[3185]: E0118 14:14:25.606734 3185 ready.go:40] Error performing healthcheck: Get https://localhost:8443/healthz: dial tcp 127.0.0.1:8443: getsockopt: connection refused
Jan 18 14:14:26 minikube localkube[3185]: I0118 14:14:26.606242 3185 ready.go:30] Performing healthcheck on https://localhost:8443/healthz
Jan 18 14:14:26 minikube localkube[3185]: E0118 14:14:26.607495 3185 ready.go:40] Error performing healthcheck: Get https://localhost:8443/healthz: dial tcp 127.0.0.1:8443: getsockopt: connection refused

10F
1738891449288956

ubuntu版本启动时候为什么会额外启动api server, etcd等三个pod,貌似这三个pod已经集成到了localkube了,所以启动报端口已经占用

feiyu199307

请问您解决这个问题了吗?

评论
11F
linglong117

minikube start --vm-driver=hyperkit --registry-mirror=https://registry.docker-cn.com 安装步骤来,start 后一切正常,电脑一重启再执行
minikube start --vm-driver=hyperkit
Starting local Kubernetes v1.9.0 cluster...
Starting VM...

卡在这就不动了
mac 系统

易立

再次启动,直接 minikube start

评论
12F
coderlong

大神,我用 minikube start --registry-mirror=https://registry.docker-cn.com -v10 启动提示这个,求解啊
image

13F
coderlong

用minikube logs -v10 提示这个:
Error getting cluster bootstrapper: getting localkube bootstrapper: getting ssh client: Error dialing tcp via ssh client: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey],hods remain。

image

14F
1438010882971626

E0320 15:06:37.328295 4352 start.go:159] Error starting host: Error starting stopped host: Maximum number of retries (5) exceeded.

15F
1438010882971626

minikube start --iso-url="https://storage.googleapis.com/minikube/minikube-0.5.iso"
Starting local Kubernetes v1.9.0 cluster...
Starting VM...
E0320 15:19:39.924060 5232 start.go:159] Error starting host: Temporary Error: Error configuring auth on host: OS type not recognized.

aa1232

请问你遇到这个问题解决了吗? 我也遇到了。

评论
16F
1401561920591526

如果使用0.25.1 minikube,就会遇到如下错误,解决方法是minikube delete,然后rm -rf ~/.minikube, 然后安装minikube 0.25.0,就可以了
Starting local Kubernetes v1.9.4 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
E0322 22:04:42.536835 4056 start.go:234] Error updating cluster: Error updating localkube from uri: Error creating localkube asset from url: Error opening file asset: /Users/king.wang/.minikube/cache/localkube/localkube-v1.9.4: open /Users/king.wang/.minikube/cache/localkube/localkube-v1.9.4: no such file or directory
E0322 22:04:42.695564 4056 util.go:151] Error uploading error message: : Post https://clouderrorreporting.googleapis.com/v1beta1/projects/k8s-minikube/events:report?key=AIzaSyACUwzG0dEPcl-eOgpDKnyKoUFgHdfoFuA: read tcp 192.168.1.4:50213->172.217.160.74:443: read: connection reset by peer

易立

本文已经更新到 0.25.2

somklkfkls

0.26.1 依然存在这个问题,是被墙了吗?

凡星点点

minikube delete

then

minikube start

fixed my issue

凡星点点

@凡星点点 发错了,好像还不能删。今天晕了,sorry

评论
17F
1690598276609305

虚拟机的登录密码是好多呢,请问下????centos的

易立

用 minikube ssh 登录

凡星点点

minikube delete

then

minikube start

fixed my issue

凡星点点

发错了,好像还不能删。今天晕了,sorry

评论
18F
jimmysong

本地kubernetes分布式集群https://github.com/rootsongjc/kubernetes-vagrant-centos-cluster

易立 赞同
19F
1254114550648251

win 10 下没法用

minikube start --insecure-registry="aw.hub" --registry-mirror="https://hub-mirror.c.163.com"
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading kubelet v1.10.0
Downloading kubeadm v1.10.0
Finished Downloading kubelet v1.10.0
Finished Downloading kubeadm v1.10.0
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
E0423 14:11:44.561338 9944 start.go:281] Error restarting cluster: restarting kube-proxy: waiting for kube-proxy to be up for configmap update: timed out waiting for the condition

凡星点点

我win7下也遇到同样问题

凡星点点

minikube delete

then

minikube start

fixed my issue

战场原礼亚

mac下也遇到这个问题了,没解决成功

易立

那个版本?@战场原礼亚

zik_kinbun

$ minikube start --vm-driver=vmwarefusion --registry-mirror=https://registry-mirror.com
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
E0809 23:46:38.198507 8690 start.go:305] Error restarting cluster: restarting kube-proxy: waiting for kube-proxy to be up for configmap update: timed out waiting for the condition

zik_kinbun

@易立 在mac上遇到同样的问题
~$ ls .minikube/cache/iso/
minikube-v0.28.1.iso

zik_kinbun

@zik_kinbun 手动指定了代理,成功了

minikube start --docker-env HTTPS_PROXY=${https://registry.docker-cn.com} --registry-mirror=https://registry-mirror.com

评论
20F
gavin宫

求助:win10在启动时报如下错误:

minikube start --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="MinikubeSwitch"
Starting local Kubernetes v1.10.0 cluster...

Starting VM...
E0424 00:40:00.537875 5188 start.go:159] Error starting host: Error starting stopped host: exit status 1.
Retrying.
E0424 00:40:00.542754 5188 start.go:165] Error starting host: Error starting stopped host: exit status 1
E0424 00:40:00.556796 5188 util.go:151] Error uploading error message: : Post https://clouderrorreporting.googleapis.com/v1beta1/projects/k8s-minikube/events:report?key=AIzaSyACUwzG0dEPcl-eOgpDKnyKoUFgHdfoFuA: read tcp 172.16.219.121:51539->216.58.200.42:443: wsarecv: An existing connection was forcibly closed by the remote host.

易立

我用0.26.1在Windows 10无法复现相关问题
minikube logs的结果是什么?

评论