Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代理环境下在 macOS 上安装 Minikube 小记 #20

Open
unknwon opened this issue May 21, 2018 · 17 comments
Open

代理环境下在 macOS 上安装 Minikube 小记 #20

unknwon opened this issue May 21, 2018 · 17 comments
Labels

Comments

@unknwon
Copy link
Owner

@unknwon unknwon commented May 21, 2018

日期:2018-05-22
更新:2018-05-22

因为实习要求需要使用 k8s,所以打算在上岗前本地安装一下 Minikube,本想着复制粘贴就能搞定。。因为代理的问题折腾了好一会,趁着还热乎赶紧备份下。

版本信息

  • macOS 10.13.4
  • Docker for Mac 18.03.1-ce
  • VirtualBox 5.2.12
  • Minikube 0.25.2

*因为当前最新版 Minikube 0.27.0 在 macOS 下可能会遇到启动集群(Starting cluster components...)一直挂起,所以我粗暴地直接回退到 0.25.2

安装组件

  1. 安装 kubectl
  2. 安装 Minikube

干跑集群

在给集群配置代理之前(当然,宿主运行着代理),干跑也是可以初始化成功的。

# 在此过程中,首次运行会下载两个文件,关键看代理速度
$ minikube start
Starting local Kubernetes v1.9.4 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.

启动完成后,你会在 VirtualBox 看到一个名叫 minikube 的虚拟机:

image

好了,可以停止集群了。

$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.

配置代理

我宿主的代理是运行在 http://127.0.0.1:1087,重新启动集群前需要注意以下问题:

  1. 代理的 HTTP 监听必须是在所有网卡上,即监听地址 0.0.0.0 而不是 127.0.0.1 或者 localhost,否则虚拟机内是连不上代理的
  2. 设置集群代理时不可使用 localhost 而是虚拟机对应的宿主 IP 地址,例如 192.168.99.1
  3. 一般而言,虚拟机的 IP 为 192.168.99.100,也需要忽略代理
  4. 集群自身的 IP 需要被设置为忽略代理,否则宿主就连不上集群了
  5. 集群的代理需要在启动时通过 -docker-env 特别指定,宿主的环境变量对集群内是不生效的

综上所述...

image

# 此两行本身就应该已经添加到你的 .bashrc 或者 .zshrc 了
$ export http_proxy="http://127.0.0.1:1087"
$ export https_proxy="http://127.0.0.1:1087"

# For Kubernetes
$ export no_proxy=192.168.99.100
$ minikube start --docker-env HTTP_PROXY=$http_proxy --docker-env HTTPS_PROXY=$https_proxy
...

# 启动集群后,还要再特别忽略集群节点的代理
$ export no_proxy=$no_proxy,$(minikube ip)
$ export NO_PROXY=$no_proxy,$(minikube ip)

忽略代理主要是针对宿主在访问集群时绕过代理,否则像这类私有 IP 地址段代理是永远不可能访问到的。。然后就会导致宿主一直无法获取到集群的状态。

参考链接

@unknwon unknwon added the Kubernetes label May 21, 2018
@Wxtrkbc

This comment has been minimized.

Copy link

@Wxtrkbc Wxtrkbc commented Jun 21, 2018

@unknwon 请问一下,上面那图你那配置http proxy 代理的软件叫什么

@unknwon

This comment has been minimized.

@M2shad0w

This comment has been minimized.

Copy link

@M2shad0w M2shad0w commented Jun 23, 2018

无闻牛再哪里实习?

@joint-song

This comment has been minimized.

Copy link

@joint-song joint-song commented Aug 14, 2018

折腾那么久的原因原来是...minikube版本太新了...mmp

@tangzhiyi11

This comment has been minimized.

Copy link

@tangzhiyi11 tangzhiyi11 commented Aug 22, 2018

设置了http_proxy还是不行。。
然后用docker自带的客户端装了下k8s,很好使,装的一点问题没有。。

@bluhar

This comment has been minimized.

Copy link

@bluhar bluhar commented Aug 23, 2018

@tangzhiyi11 能具体说说装的哪个image吗

@tangzhiyi11

This comment has been minimized.

Copy link

@tangzhiyi11 tangzhiyi11 commented Aug 23, 2018

@bluhar 代理设置的不对所有image都下载不下来吧,我需要用的是mysql,一直无法跑起来

@losymear

This comment has been minimized.

Copy link

@losymear losymear commented Sep 3, 2018

minikube logs里错误proxyconnect tcp: dial tcp 127.0.0.1:1087: getsockopt: connection refused"该如何处理?
按照docker配置代理这样设置可以了,不过奇怪的是127.0.0.1不行。

@eic-aibee

This comment has been minimized.

Copy link

@eic-aibee eic-aibee commented Nov 30, 2018

设置集群代理时不可使用 localhost 而是虚拟机对应的宿主 IP 地址,例如 192.168.99.1
这个为什么被划掉了,这个应该是必要的。

@unknwon

This comment has been minimized.

Copy link
Owner Author

@unknwon unknwon commented Nov 30, 2018

设置集群代理时不可使用 localhost 而是虚拟机对应的宿主 IP 地址,例如 192.168.99.1
这个为什么被划掉了,这个应该是必要的。

有点记不太清了。。好像是设置了也没啥用必须用 --docker-env 传进去什么的。。

@hy05190134

This comment has been minimized.

Copy link

@hy05190134 hy05190134 commented Apr 15, 2019

@unknwon 如果我是 Mac + 蓝灯翻墙的,如何设置 http 代理呢?

@hy05190134

This comment has been minimized.

Copy link

@hy05190134 hy05190134 commented Apr 15, 2019

@unknwon 原来蓝灯也是有代理端口的,不过你说的需要设置 0.0.0.0 其实网上说可以通过 10.0.2.2(NAT 的模式下指向 127.0.0.1) 也是可以拉取到镜像的

@unknwon

This comment has been minimized.

Copy link
Owner Author

@unknwon unknwon commented Apr 15, 2019

@hy05190134 6666 没有用过蓝灯。。就不太懂了

@edwardstudy

This comment has been minimized.

Copy link

@edwardstudy edwardstudy commented Apr 29, 2019

设置集群代理时不可使用 localhost 而是虚拟机对应的宿主 IP 地址,例如 192.168.99.1
这条还有用呀

@zhaozhi406

This comment has been minimized.

Copy link

@zhaozhi406 zhaozhi406 commented May 13, 2019

多谢代理设置的提醒,弄好了;但是docker-env应该设置为宿主机对应的虚拟机地址,比如 192.168.99.1

@win5do

This comment has been minimized.

Copy link

@win5do win5do commented May 22, 2019

VM的ip是192.168.99.100
在宿主机上ifconfig有一条192.168.99.1
代理可配置为export {HTTP,HTTPS,FTP}_PROXY=http://192.168.99.1:1080

@unknwon

This comment has been minimized.

Copy link
Owner Author

@unknwon unknwon commented Aug 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.