从docker容器中代理后面的minikube虚拟机内部连接到外部网络



我在Minikube VM中有一个活动的kubernetes集群(使用VirtualBox作为驱动程序(,所以为了部署新的容器,我可以下载映像,因为这个连接已经使用istio服务布局,现在,如果我首先ssh到我的minikube虚拟机中,我无法wget https内容,但在设置代理和no_oproxys后连接了http内容,但如果我想从容器内部访问任何链接,比如说带有python映像和urllib库的简单pod,我想从这个pod内部连接,然后打印任何链接的内容(例如。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作为-

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

在设置env变量之后。

更新:我创建了一个不同的容器,只是为了从组件内部检查卷曲,作为-(我使用kfp库来创建容器(

def curl_op(text):
return dsl.ContainerOp(
name='curl',
image='tutum/curl',
command=['sh', '-c'],
arguments=['curl -x http://<proxy-server>:<proxy-port> "$0"', text]
)

因此,使用上面的参数,我可以连接到外部链接,这再次确定我需要创建带有代理集的容器。

因此,为了运行我提到的作为管道组件的上述python代码。我使用操作系统库添加了环境变量,这篇文章能够连接到外部网络。更新的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映像是在没有管道库函数帮助的情况下从头开始创建的,那么我们只需要在基本映像调用之后以通常的方式将env详细信息添加到我们的docker文件中

ENV HTTP_PROXY http://proxy-path:port
ENV HTTPS_PROXY http://proxy-path:port

相关内容

  • 没有找到相关文章

最新更新