Can I add service name aliases in K8s DNS the same way links can have aliases in Docker?

12/8/2016

In Docker a client container can refer to a server container by different names by using link aliasing:

--link server-container:my_preferred_server

A second client can use its own choice of names

-- link server-container:server

Can I achieve this in K8s preferably by adding different records in K8s's DNS?

Note the solution we are using now is having the client containers not use a hardcoded name for the server container, but use the value of an env variable SERVER_HOSTNAME='server-container' and link without aliasing:

--link server_container

Edit: To answer to some of the questions got in the replies:
* there is more than one client container, otherwise aliasing would have no purpose. Each client knows the server by a different name
* the client and the server are not in the same pod

-- lcfd
kube-dns
kubernetes

1 Answer

12/8/2016

There are a few ways to achieve that.

  • You can simply create a Service for the server container (in its own Pod), if the Pod is in the same Kubernetes cluster then a typical Service will do, if the server container is outside of Kubernetes, you can create a Service with ExternalIPs to define the IPs of the endpoints

  • If this is side-by-side deployment (i.e. 1 client <-> 1 server) you might consider keeping the client and server in the same Pod definition: in a single Pod, the client container can reach the server container via localhost on its specific port.

  • You can fiddle with kube-dns to inject arbitrary dns names (or even overwrite public ones), but you should really not have to do this.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow