简体   繁体   中英

Is there an equivalent of host.docker.internal for Kubernetes cluster running as part of Windows Docker Desktop

Usecase: I have a Docker desktop and kubernetes enabled within it. From the kubernetes node, I want to connect to a database running on my laptop without using my laptop's ip address.

I want to refer to the Windows Host machine from within Kuberntes Endpoint without using the dynamic IP of the host. In docker there is a special DNS name host.docker.internal that allows host machine endpoints to be connected. I am not able to specify this for the endpoint IP. Is there something equivalent in Kubernetes?

Use host.docker.internal .

I've tested on Mac, but it should work the same for Windows.

  1. 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
  2. Start a simple web server.

     mkdir /tmp/server cd /tmp/server echo "hi" > index.html python -m SimpleHTTPServer 8000
  3. Access the web server from the alpine pod.

     kubectl exec -it alpine -- sh wget host.docker.internal:8000 cat index.html

您可以使用远程呈现来实现这一点, https://www.telepresence.io/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM