Sobes.tech
Senior

How to access a Pod inside a Kubernetes cluster from another Pod?

sobes.tech AI

Answer from AI

In Kubernetes, to access a Pod from another Pod, a Service is usually used, which provides a stable DNS name and load balancing. Direct access by Pod IP is not recommended, as the IP may change.

Example:

  • A Service named my-service is created, pointing to the desired Pod or set of Pods.
  • In another Pod, you can access it via the DNS name my-service.namespace.svc.cluster.local (where namespace is the namespace).

If you still need to access the Pod directly, you can use its IP, but this is unreliable.

Example of accessing a service from a Pod:

curl http://my-service.namespace.svc.cluster.local:port

Thus, the correct way is to use Kubernetes Service and DNS for communication between Pods within the cluster.

How to access a Pod inside a Kubernetes cluster from… - sobes.tech