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

7.6k views Asked by At

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?

2

There are 2 answers

1
Thomas On

You can achieve this using telepresence, https://www.telepresence.io/

1
crenshaw-dev On

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, on the host.

    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 -O- host.docker.internal:8000