Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 335
lcfd Avatar asked Dec 08 '16 09:12

lcfd


1 Answers

I just had the same need and I was able to add an external Service, which points to the FQDN of the other service within the cluster:

apiVersion: v1
kind: Service
metadata:
  name: "my-alias"
spec:
  type: ExternalName
  externalName: "other-service.my-namespace.svc.cluster.local"

Now, I can access other-service as my-alias from within the cluster and namespace.

like image 99
matlehmann Avatar answered Oct 19 '22 21:10

matlehmann