<p>I have a kubernetes kind cluster with the following configuration:</p>
<pre><code>kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    kubeadmConfigPatches:
      - |
        kind: InitConfiguration
        imageGCHighThresholdPercent: 70
        evictionHard:
          nodefs.available: &quot;0%&quot;
          nodefs.inodesFree: &quot;0%&quot;
          imagefs.available: &quot;70%&quot;
        nodeRegistration:
          kubeletExtraArgs:
            node-labels: &quot;ingress-ready=true&quot;
    extraPortMappings:
      - containerPort: 80
        hostPort: 80
        protocol: TCP
      - containerPort: 443
        hostPort: 443
        protocol: TCP
</code></pre>
<p>Image version: <code>docker.io/kindest/base:v20220305-b67a383f</code></p>
<p>I am trying to connect to my localhost by using <code>ExternalName</code>:</p>
<pre><code>kind: Endpoints
apiVersion: v1
metadata:
  name: my-external-service
subsets:
  - addresses:
      - ip: 10.0.2.2
    ports:
      - port: 8080
---
kind: Service
apiVersion: v1
metadata:
  name: my-external-service
  labels:
    app: my-external-service
spec:
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP

</code></pre>
<p>According to this answer: <a href="https://stackoverflow.com/questions/9808560/why-do-we-use-10-0-2-2-to-connect-to-local-web-server-instead-of-using-computer/34732276#34732276">why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client</a>, that IP should be the localhost in my local machine.</p>
<p>Then I run a container to debug this setup:</p>
<pre><code>kubectl run -i --tty --rm debug --image=alpine --restart=Never -- sh
</code></pre>
<p><code>8.8.8.8</code> is pingable, but unfortunately I cannot ping <code>10.0.2.2</code>.</p>
<p>What am I doing wrong?</p>

Matteo
<p>Turns out it was not a kubernetes problem, but a docker one <strong>since I am running Kind</strong>. The solution is described in this github comment: <a href="https://github.com/kubernetes-sigs/kind/issues/1200#issuecomment-647145134" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/kind/issues/1200#issuecomment-647145134</a></p>
<p>the address is not <code>10.0.2.2</code>, but <code>172.17.0.1</code> which is your docker bridge default gateway.</p>
<p>Also we need to add this <code>iptables</code> rule <strong>in the host machine</strong></p>
<pre><code>iptables -I INPUT -p tcp --dport &lt;your server port&gt; -j ACCEPT
</code></pre>
