I am trying to automate the process of dynamically bring up two containers in a Kubernetes cluster using open-source images. Since the images are third party images, I have some limitations to what can be configured. I also need these containers to come up inside different pods.
For the sake of this discussion, I will call these containers container a.domain.com
and container b.domain.com
. Container A and B need to communicate back and forth and this communication is secured using TLS Certificates.
To enable this communication, I have to add the following code snippet to the spec to of my Kubernetes deployment doc.
#deployment doc for a.domain.com
spec:
hostAliases:
- ip: <Insert IP address for b.domain.com>
hostnames:
- "b.domain.com"
#deployment doc for b.domain.com
spec:
hostAliases:
- ip: <Insert IP address for a.domain.com>
hostnames:
- "a.domain.com"
If this code is missing, I get the following errors:
Error on container a.domain.com: No such host - b.domain.com
Error on container b.domain.com: No such host - a.domain.com
Since, both my containers have to come up together, I cannot hardcode the IP address in the yaml file.
Is there anyway I can add a parameter to the deployment docs for these containers that allows me to deterministically pre-configure the IP address that the pods use when they come up?
Posting the OP's comment as an answer (community wiki):
I finally figured it out. Using service-name.namespace instead of service-name.namespace.svc.cluster.local solved the issue for me.