Does a pod pass through service for outbound traffic?

12/3/2019

Inbound traffic is pass through the service before going to pods. How about the outbound traffic such as a pod accessing

  • pods outside the service in the same node
  • pods outside the service in different node
  • outside the cluster

does it pass through the service first? If yes, the only reason i can see now if for monitoring and logging or there is anything else?

-- letthefireflieslive
kubernetes

1 Answer

12/3/2019

I think you can distinguish two cases here:

1. Responses from Pod behind a Service

If a client makes a request to a Service, the request is routed to one of the Pods behind the Service. The response from this Pod to the client "passes through the Service" again.

The reason is that the source IP address of the IP datagram has to be changed from the Pod's IP address to the Service's IP address. This is to make the actual Pods that implement a Service transparent to the client. For the client it looks as if the Service IP address and port is a single server and it communicates directly with it.

2. A Pod making an independent request

If a Pod makes an independent request, this request doesn't pass through the Service but directly goes to whatever IP address the Pod is requesting.

For example, if a Pod makes a direct request to another Pod in the cluster, the destination IP address of the request is this Pod's IP address. If a Pod makes a request to a Service in the cluster, the destination IP address of the request is this Service's IP address. If a Pod makes a request to a destination outside the cluster, the destination IP address of the request is the IP address of this external destination.

-- weibeld
Source: StackOverflow