tmp dev
tmp dev

Reputation: 9193

accessing host machine from a pod running on a kind cluster

I'm running a kind cluster and from one of the pods I need to access the host machine. I know in minikube you can access it using 10.0.0.2 is there some way I can access it, the same way I could use host.docker.internal on Docker Desktop?

Upvotes: 6

Views: 6690

Answers (2)

Vit
Vit

Reputation: 8411

Check Is it possible accessing host machine ports from Kind pods? , that most probably solution you are looking for.

  1. workaround using qoomon/docker-host
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dockerhost
  labels:
    k8s-app: dockerhost
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: dockerhost
  template:
    metadata:
      labels:
        k8s-app: dockerhost
    spec:
      containers:
      - name: dockerhost
        image: qoomon/docker-host
        securityContext:
          capabilities:
            add: ["NET_ADMIN", "NET_RAW"]
        env:
        # Not needed in MacOs:
        - name: DOCKER_HOST
           value: 172.17.0.1 # <-- docker bridge network default gateway

---
apiVersion: v1
kind: Service
metadata:
  name: dockerhost
spec:
  clusterIP: None # <-- Headless service
  selector:
    k8s-app: dockerhost
  1. check iptables way

kind pod with a container name: test

local container: myapp exposing port 8081

Allow port in the firewall

iptables -I INPUT -p tcp --dport 8081 -j ACCEPT now from inside container test in kind cluster, you can run:

curl 172.17.0.1:8081

where 172.17.0.1 is your docker bridge default gateway.

Upvotes: 1

kus
kus

Reputation: 504

Docker uses default subdomain 172.17.0.0/16, and assign the pods IP address 172.17.X.X

Host server can be access using ip address 172.17.0.1

Upvotes: 3

Related Questions