从 docker 容器中代理后面的 minikube VM 内部连接到外部网络
Connecting to external networks from inside minikube VM behind proxy in docker container
我在 Minikube VM 中有一个活动的 kubernetes 集群(使用 VirtualBox 作为驱动程序),所以为了部署新容器,我可以下载图像,因为这个连接已经使用 istio 服务布局,现在如果我 ssh 到我的minikube VM 首先,我无法获取 https 内容,但是在设置代理和 no_proxies 后连接了 http 内容,但是如果我想从我的容器内部访问任何 link,请说简单的 pod 与 python 图像和 urllib 库,我想从这个 pod 内部连接,然后从任何 link (eg.http://python.org) 打印内容我无法做到所以,我得到的只是日志中没有主机错误的路由,这表明由于代理导致连接出现问题。
def basic():
import urllib.request
print("inside basic funtion")
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)
这是 python 代码,我是 运行 来自容器内部的管道组件。
我最近遇到的错误-
Traceback (most recent call last):
File "/usr/local/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/usr/local/lib/python3.7/http/client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/local/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "<string>", line 3, in basic
File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/local/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.7/urllib/request.py", line 1345, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/local/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Operation timed out>
我已经启动了 minikube as-
minikube start --cpus 6 --memory 12288 --disk-size=80g --extra-config=apiserver.service-account-issuer=api --extra-config=apiserver.service-account-signing-key-file=/var/lib/minikube/certs/apiserver.key --extra-config=apiserver.service-account-api-audiences=api --kubernetes-version v1.14.0
设置环境变量后。
更新:
我创建了一个不同的容器只是为了检查组件内部的卷曲 - (我正在使用 kfp 库创建容器)
def curl_op(text):
return dsl.ContainerOp(
name='curl',
image='tutum/curl',
command=['sh', '-c'],
arguments=['curl -x http://<proxy-server>:<proxy-port> "[=14=]"', text]
)
所以使用上面的参数我可以连接到外部 links,这再次确定我需要创建带有代理集的容器。
所以对于 运行 上面的 python 代码我提到作为管道组件。
我使用 os 库添加了环境变量,这个单独的部分能够连接到外部网络。
更新了 python 代码 -
def basic():
import urllib.request
import os
proxy = 'http://proxy-path:port'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
print("inside basic funtion")
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)
并且如果 docker 图像是在没有借助管道库函数的情况下从头开始创建的,那么我们只需要在基本图像调用之后以通常的方式将环境细节添加到我们的 docker 文件中-
ENV HTTP_PROXY http://proxy-path:port
ENV HTTPS_PROXY http://proxy-path:port
我在 Minikube VM 中有一个活动的 kubernetes 集群(使用 VirtualBox 作为驱动程序),所以为了部署新容器,我可以下载图像,因为这个连接已经使用 istio 服务布局,现在如果我 ssh 到我的minikube VM 首先,我无法获取 https 内容,但是在设置代理和 no_proxies 后连接了 http 内容,但是如果我想从我的容器内部访问任何 link,请说简单的 pod 与 python 图像和 urllib 库,我想从这个 pod 内部连接,然后从任何 link (eg.http://python.org) 打印内容我无法做到所以,我得到的只是日志中没有主机错误的路由,这表明由于代理导致连接出现问题。
def basic():
import urllib.request
print("inside basic funtion")
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)
这是 python 代码,我是 运行 来自容器内部的管道组件。
我最近遇到的错误-
Traceback (most recent call last):
File "/usr/local/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/usr/local/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/usr/local/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/usr/local/lib/python3.7/http/client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/local/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/usr/local/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "<string>", line 3, in basic
File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/local/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.7/urllib/request.py", line 1345, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/local/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 110] Operation timed out>
我已经启动了 minikube as-
minikube start --cpus 6 --memory 12288 --disk-size=80g --extra-config=apiserver.service-account-issuer=api --extra-config=apiserver.service-account-signing-key-file=/var/lib/minikube/certs/apiserver.key --extra-config=apiserver.service-account-api-audiences=api --kubernetes-version v1.14.0
设置环境变量后。
更新: 我创建了一个不同的容器只是为了检查组件内部的卷曲 - (我正在使用 kfp 库创建容器)
def curl_op(text):
return dsl.ContainerOp(
name='curl',
image='tutum/curl',
command=['sh', '-c'],
arguments=['curl -x http://<proxy-server>:<proxy-port> "[=14=]"', text]
)
所以使用上面的参数我可以连接到外部 links,这再次确定我需要创建带有代理集的容器。
所以对于 运行 上面的 python 代码我提到作为管道组件。 我使用 os 库添加了环境变量,这个单独的部分能够连接到外部网络。 更新了 python 代码 -
def basic():
import urllib.request
import os
proxy = 'http://proxy-path:port'
os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
print("inside basic funtion")
with urllib.request.urlopen('http://python.org/') as response:
html = response.read()
print(html)
并且如果 docker 图像是在没有借助管道库函数的情况下从头开始创建的,那么我们只需要在基本图像调用之后以通常的方式将环境细节添加到我们的 docker 文件中-
ENV HTTP_PROXY http://proxy-path:port
ENV HTTPS_PROXY http://proxy-path:port