应用场景: 我有一个启用Kubernetes的Docker桌面。我想从Kubernetes节点连接到运行在我的笔记本电脑上的数据库,而不使用笔记本电脑的IP地址。
我希望在Kubernetes终点内引用Windows Host机器,而不使用主机的动态IP。在Docker中,有一个特殊的DNS名称host.docker.internal,允许连接主机机器终点。但我无法为终点IP指定该名称。 Kubernetes中是否有类似的东西?
应用场景: 我有一个启用Kubernetes的Docker桌面。我想从Kubernetes节点连接到运行在我的笔记本电脑上的数据库,而不使用笔记本电脑的IP地址。
我希望在Kubernetes终点内引用Windows Host机器,而不使用主机的动态IP。在Docker中,有一个特殊的DNS名称host.docker.internal,允许连接主机机器终点。但我无法为终点IP指定该名称。 Kubernetes中是否有类似的东西?
使用host.docker.internal
。
我在Mac上测试过,但Windows应该也可以使用相同的方法。
Spin up an alpine pod (deployment yaml borrowed from rossbackp).
apiVersion: v1
kind: Pod
metadata:
name: alpine
namespace: default
spec:
containers:
- image: alpine:3.2
command:
- /bin/sh
- "-c"
- "sleep 60m"
imagePullPolicy: IfNotPresent
name: alpine
restartPolicy: Always
kubectl apply -f deployment.yaml # after saving the above file as deployment.yaml
Start a simple web server, on the host.
mkdir /tmp/server
cd /tmp/server
echo "hi" > index.html
python -m SimpleHTTPServer 8000
Access the web server from the alpine pod.
kubectl exec -it alpine -- sh
wget -O- host.docker.internal:8000
您可以使用远程实时技术 https://www.telepresence.io/ 来实现此目标。