<p>I'm trying to move my development environment to Kubernetes to be more in line with existing deployment stages. In that context I need to call a service by its Ingress DNS name internally, while this DNS name resolves to an IP unreachable from the cluster itself.  I would like to create a DNS alias inside the cluster which would point to the service, basically a reversal of a <code>ExternalName</code> service.</p>
<p>Example:</p>
<ul>
<li>The external DNS name is <code>my-service.my-domain.local</code>, resolving to 127.0.0.1</li>
<li>Internal service is <code>my-service.my-namespace.svc.cluster.local</code></li>
<li>A process running in a pod can't reach <code>my-service.my-domain.local</code> because of the resolved IP, but could reach <code>my-service.my-namespace.svc.cluster.local</code>, but needs to be accessing the former by name</li>
<li>I would like to have a cluster-internal DNS name <code>my-service.my-domain.local</code>, resolving to the service <code>my-service.my-namespace.svc.cluster.local</code> (<code>ExternalName</code> service would do the exact opposite).</li>
</ul>
<p>Is there a way to implement this in Kubernetes?</p>

Nikolai Prokoschenko
<p>You can use the core dns and add the entry over there using configmap</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  annotations:
  labels:
    eks.amazonaws.com/component: coredns
    k8s-app: kube-dns
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    domain-name:port {
        errors
        cache 30
        forward . &lt;IP or custom DNS&gt;
        reload
    }
</code></pre>
<p>To test you can start one busy box pod</p>
<pre><code>kubectl run busybox --restart=Never --image=busybox:1.28 -- sleep 3600
</code></pre>
<p>hit the domain name from inside of busy box</p>
<pre><code>kubectl exec busybox -- nslookup domain-name
</code></pre>
<p>Official doc ref : <a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/</a></p>
<p>Nice article for ref : <a href="https://coredns.io/2017/05/08/custom-dns-entries-for-kubernetes/" rel="nofollow noreferrer">https://coredns.io/2017/05/08/custom-dns-entries-for-kubernetes/</a></p>
<p>Or</p>
<p>you can map the domain to the <strong>service name</strong> using rewrite, <code>rewrite name example.io service.default.svc.cluster.local</code></p>
<blockquote>
<p>Use the Rewrite plug-in of CoreDNS to resolve a specified domain name
to the domain name of a Service.</p>
</blockquote>
<pre><code>apiVersion: v1
data:
  Corefile: |-
    .:5353 {
        bind {$POD_IP}
        cache 30
        errors
        health {$POD_IP}:8080
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        rewrite name example.io service.default.svc.cluster.local
        loadbalance round_robin
        prometheus {$POD_IP}:9153
        forward . /etc/resolv.conf
        reload
    }
kind: ConfigMap
metadata:
  labels:
    app: coredns
    k8s-app: coredns
    kubernetes.io/cluster-service: &quot;true&quot;
    kubernetes.io/name: CoreDNS
    release: cceaddon-coredns
  name: coredns
  namespace: kube-system
</code></pre>
