4

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).

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

  web:
    image: webimage
    command: run start
    build:
      context: ./web
      dockerfile: Dockerfile

In front of this, I have a reverse-proxy server running Apache Traffic Server. There is a simple mapping rule in the url remapping config file

map / http://web/

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

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: {}

...traffic server complains because it cannot resolve the DNS name web.

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

CONFIG proxy.config.dns.search_default_domains INT 1

(see https://docs.trafficserver.apache.org/en/7.1.x/admin-guide/files/records.config.en.html#dns)

This config change is described as follows:

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.

Now everything works just great in kubernetes.

However, when running in docker-compose, traffic-server complains about not being able to resolve web.

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.

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

spender
  • 117,338
  • 33
  • 229
  • 351

2 Answers2

2

The default kubernetes local domain is

default.svc.cluster.local

which means that the fully qualified name of the web service under kubernetes is web.default.svc.cluster.local

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

version: "3"
services:
  web:
    # ...
  trafficserver:
    # ...
    links:
      - "web:web.default.svc.cluster.local"

and update the mapping config in trafficserver to:

map / http://web.default.svc.cluster.local/

and now the web service is reachable using the same domain name across docker-compose and kubernetes.

spender
  • 117,338
  • 33
  • 229
  • 351
1

I found the same problem but solved it in another way, after much painful debugging.

With CONFIG proxy.config.dns.search_default_domains INT 1 Apache Traffic Server will append the names found under search in /etc/resolve.conf one by one until it gets a hit.

In my case resolve.conf points to company.intra so I could name my services (all services used from Apache Traffic Server) according to this

version: '3.2'
services:
   # this hack is ugly but we need to name this 
   # (and all other service called from ats), with 
   # the same name as found under search in /etc/resolve.conf)
   web.company.intra:
      image: web-image:1.0.0

With this change I don't need to make any changes to remap.config at all, the URL used can still be only "web", since it gets expanded to a name that matches both environments,
web.company.intra in docker.compose
web.default.svc.local.cluster in kubernetes

Andreas Wederbrand
  • 38,065
  • 11
  • 68
  • 78