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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With