Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从docker容器中访问k3d Kubernetes群集?_Docker_Kubernetes - Fatal编程技术网

如何从docker容器中访问k3d Kubernetes群集?

如何从docker容器中访问k3d Kubernetes群集?,docker,kubernetes,Docker,Kubernetes,我有一个运行的k3d Kubernetes群集: $ kubectl cluster-info Kubernetes master is running at https://0.0.0.0:6550 CoreDNS is running at https://0.0.0.0:6550/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy Metrics-server is running at https://0.0.0.0:655

我有一个运行的k3d Kubernetes群集:

$ kubectl cluster-info
Kubernetes master is running at https://0.0.0.0:6550
CoreDNS is running at https://0.0.0.0:6550/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://0.0.0.0:6550/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
我有一个python脚本,它使用kubernetes客户端api并管理名称空间、部署、pod等。这在我的本地环境中运行良好,因为我安装了所有必要的python模块,并且可以直接访问本地k8s群集。我的目标是容器化,以便在同事的系统上成功地运行相同的脚本

在docker容器中运行相同的python脚本时,我收到连接错误:

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='172.17.0.1', port=6550): Max retries exceeded with url: /api/v1/namespaces (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f8b637c5d68>: Failed to establish a new connection: [Errno 113] No route to host',))
urllib3.exceptions.MaxRetryError:HTTPSConnectionPool(host='172.17.0.1',port=6550):url:/api/v1/命名空间超过了最大重试次数(由NewConnectionError引起(':未能建立新连接:[Errno 113]没有到主机的路由',))
172.17.0.1
是我的
docker0
网桥地址,因此假定它将解析或转发流量到我的本地主机。我已尝试从本地
.kube/config
加载k8s配置,该配置引用了
服务器:https://0.0.0.0:6550
并使用
服务器创建单独的配置文件:https://172.17.0.1:6550
和两者都给出了相同的
无主机路由
错误(各自的ip地址在HTTPSConnectionPool中(主机=…)

我提出的一个想法是在容器外部运行socat进程,从容器内部通过从外部安装的桥插座传输流量,但我需要使用的docker映像似乎没有安装socat。然而,我感觉真正的解决方案应该比所有这些简单得多


当然,还有其他docker容器实例需要访问docker网络外部提供服务的k8s群集。通常如何建立此连接?

使用
docker network
命令创建预定义网络

您可以传递
--network
以将k3d连接到现有的Docker网络,也可以传递
Docker run
以对另一个容器执行相同的操作