How Can One Pod Call Another Pod or Service with a Specific URL in Kubernetes?
Asked by
Jumblebee
I'm trying to figure out how to connect my services within Kubernetes. The setup I have is: when a user types in 'mydomain.com', Ingress routes the request to Service A, which then communicates with Pod A. From there, Pod A needs to call Service B, which then calls Pod B. However, when Pod B tries to return to the original URL 'mydomain.com', I want it to go back to Service A or Pod A, but not the Ingress directly. I attempted to create a service using the URL 'mydomain.com', but it doesn't allow dots. How can I achieve this routing within Kubernetes?
Answers
Instead of public domains, always reference the Kubernetes services to avoid routing problems. If you have a bit of control over your application calls, that would simplify things a lot!
Reply to this answer
Try adding a DNS rule in CoreDNS to manage your internal calls more effectively. This can help with services trying to call each other.
Reply to this answer
When Pod B needs to call Pod A, you'll want to use the Kubernetes DNS name for Service A instead of the public domain. The main thing here is to ensure youโre working within the cluster's networking. Calling the public domain just wonโt work from the cluster.
rOvingReporter: Exactly! Use the format 'SERVICENAME.NAMESPACE.svc.cluster.local' to reach the services without any issues.
82_Coastline: And donโt forget about the internal DNS. Thatโll help with routing properly between your services.
Reply to this answer
Another approach is to utilize the internal cluster DNS directly. Avoid any references to the public domain inside your clusterโit'll save you a lot of headaches!
Reply to this answer
Add your answer
Answers are reviewed before publication.
H3.neighborhood: For sure! Using cluster DNS is key here.
subsection C: You might also want to check out adding a rewrite rule in CoreDNS if you want to tweak DNS resolution.