<p>Is it possible to have a service name under <code>hostAliases</code> in Kubernetes? I want to point a non-existent domain name to a service instead of an IP.</p>

<p>Something like the following:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-name
spec:
  replicas: 1
  template:
    spec:
      containers:
        hostAliases:
        - ip: "my-service-name"
          hostnames:
          - "my.domain.com"
</code></pre>

<p>If not, how would you guys set up a local hosts file entry for a pod to a service? I need to resolve the <strong>non-existent</strong> domain to the service.</p>

Neekoy
<p>As @VKR explained in the other comment, HostAliases basically just injects into /etc/hosts which only allows for A-record type entries.</p>

<p>For CNAME entries, a workaround is to inject the alias into CoreDNS.</p>

<p>This can be done by editing the ConfirMap for CoreDNS:</p>

<pre><code>$ kubectl edit configmap coredns -n kube-system

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        rewrite name orderer0.example.com orderer0-example-com.orbix-mvp.svc.cluster.local
        rewrite name peer0.example.com peer0-example-com.orbix-mvp.svc.cluster.local
        kubernetes cluster.local {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
    }
</code></pre>

<p>I've added the two lines that start with <code>rewrite name</code> and once CoreDNS is restarted, the new entries are available throughout the cluster.</p>

<p>CoreDNS can be restarted using the following command:</p>

<p><code>kubectl exec -n kube-system coredns-980047985-g2748 -- kill -SIGUSR1 1</code></p>

<p>The above needs to be ran for both of the CoreDNS pods.</p>
