<p><em>As far as I'm concerned, this is more of a development question than a server question, but it lies very much on the boundary of the two, so feel free to migrate to serverfault.com if that's the consensus).</em></p>

<p>I have a service, let's call it <code>web</code>, and it is declared in a <code>docker-compose.yml</code> file as follows:</p>

<pre><code>  web:
    image: webimage
    command: run start
    build:
      context: ./web
      dockerfile: Dockerfile
</code></pre>

<p>In front of this, I have a reverse-proxy server running Apache Traffic Server. There is a simple mapping rule in the <a href="http://%20https://docs.trafficserver.apache.org/en/latest/admin-guide/files/remap.config.en.html" rel="nofollow noreferrer">url remapping config file</a></p>

<pre><code>map / http://web/
</code></pre>

<p>So all incoming requests are mapped onto the <code>web</code> service described above. This works just peachily in <code>docker-compose</code>, however when I move the service to kubernetes with the following service description:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    io.kompose.service: web
  name: web
spec:
  clusterIP: None
  ports:
  - name: headless
    port: 55555
    targetPort: 0
  selector:
    io.kompose.service: web
status:
  loadBalancer: {}
</code></pre>

<p>...traffic server complains because it cannot resolve the DNS name <code>web</code>.</p>

<p>I can resolve this by slightly changing the DNS behaviour of traffic server with the following config change:</p>

<pre><code>CONFIG proxy.config.dns.search_default_domains INT 1
</code></pre>

<p>(see <a href="https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/files/records.config.en.html#dns" rel="nofollow noreferrer">https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/files/records.config.en.html#dns</a>)</p>

<p>This config change is described as follows:</p>

<blockquote>
  <p>Traffic Server can attempt to resolve unqualified hostnames by expanding to the local domain. For example if a client makes a request to an unqualified host (e.g. host_x) and the Traffic Server local domain is y.com, then Traffic Server will expand the hostname to host_x.y.com.</p>
</blockquote>

<p>Now everything works just great in kubernetes.</p>

<p>However, when running in <code>docker-compose</code>, traffic-server complains about not being able to resolve <code>web</code>.</p>

<p>So, I can get things working on both platforms, but this requires config changes to do so. I could fire a start-up script for traffic-server to establish if we're running in kube or docker and write the config line above depending on where we are running, but ideally, I'd like the DNS to be consistent across platforms. My understanding of DNS (and in particular, DNS default domains/ local domains) is patchy.</p>

<p>Any pointers? Ideally, a local domain for docker-compose seems like the way to go here.</p>

<p>The default kubernetes local domain is</p>

<pre><code>default.svc.cluster.local
</code></pre>

<p>which means that the fully qualified name of the <code>web</code> service under kubernetes is <code>web.default.svc.cluster.local</code></p>

<p>So, in the <code>docker-compose</code> file, under the trafficserver config section, I can create an alias for <code>web</code> as <code>web.default.svc.cluster.local</code> with the following <code>docker-compose.yml</code> syntax:</p>

<pre><code>version: "3"
services:
  web:
    # ...
  trafficserver:
    # ...
    links:
      - "web:web.default.svc.cluster.local"
</code></pre>

<p>and update the mapping config in trafficserver to:</p>

<pre><code>map / http://web.default.svc.cluster.local/
</code></pre>

<p>and now the <code>web</code> service is reachable using the same domain name across <code>docker-compose</code> and <code>kubernetes</code>.</p>
