<p>I am trying to connect a pod which is running in <strong>Kind</strong> with a local Postgres database which runs in a Docker container. I tried to add the following service but the pod still cannot connect when using the DNS name <code>postgres.dev.svc</code>.</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: postgres
  namespace: dev
spec:
  type: ExternalName
  externalName: 10.0.2.2
</code></pre>
<p>Is there another way to connect these two components?</p>

ammerzon
<p>First of all it's not the correct usage of the <code>ExternalName</code> service type. Although putting an IP address in <code>externalName</code> field it's perfectly feasible  i.e. the resource will be created and you won't get any complaint from kubernetes API server. ❗<strong>But this value is treated as a domain name, comprised of digits, not as an IP adress</strong>. You can read about it in <a href="https://kubernetes.io/docs/concepts/services-networking/service/#externalname" rel="nofollow noreferrer">the official kubernetes docs</a>:</p>
<blockquote>
<p><strong>Note:</strong> ExternalName accepts an IPv4 address string, but as a DNS names comprised of digits, not as an IP address. ExternalNames that
resemble IPv4 addresses are not resolved by CoreDNS or ingress-nginx
because ExternalName is intended to specify a canonical DNS name. To
hardcode an IP address, consider using <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">headless
Services</a>.</p>
</blockquote>
<p>So what you really need here is <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">Service without a selector</a>:</p>
<blockquote>
<p>Services most commonly abstract access to Kubernetes Pods, but they
can also abstract other kinds of backends. For example:</p>
<ul>
<li>You want to have an external database cluster in production, but in your test environment you use your own databases.</li>
<li>You want to point your Service to a Service in a different  <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces" rel="nofollow noreferrer">Namespace</a>
or on another cluster.</li>
<li>You are migrating a workload to Kubernetes. While evaluating the approach, you run only a portion of your backends in Kubernetes.</li>
</ul>
<p>In any of these scenarios you can define a Service  <em>without</em>  a Pod
selector. For example:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
</code></pre>
<p>Because this Service has no selector, the corresponding Endpoints
object is not created automatically. You can manually map the Service
to the network address and port where it's running, by adding an
Endpoints object manually:</p>
<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: 192.0.2.42
    ports:
      - port: 9376
</code></pre>
</blockquote>
<p>In your particular case your <code>Service</code> definition may look as follows:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
</code></pre>
<p>and the corresponding <code>Endpoints</code> object may look like this:</p>
<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: postgres
subsets:
  - addresses:
      - ip: 10.0.2.2
    ports:
      - port: 5432
</code></pre>
<p>Of course the IP address <code>10.0.2.2</code> must be reachable from within your kubernetes cluster.</p>
