Search code examples
kubernetesgoogle-cloud-platformnat

GCP Cluster ip address is not the same as request's remoteAddr


I have a node in Google Cloud Platform Kubernetes public cluster. When I make HTTP request from my application to external website, nginx in that website shows some IP address different than the IP address of my kubernetes cluster. I can't figure out where that IP address comes from. I'm not using NAT in GCP.


Solution

  • I will just add some official terminology to put some light on GKE networking before providing an answer;

    Let's have a look at some GKE networking terminology:

    The Kubernetes networking model relies heavily on IP addresses. Services, Pods, containers, and nodes communicate using IP addresses and ports. Kubernetes provides different types of load balancing to direct traffic to the correct Pods. All of these mechanisms are described in more detail later in this topic. Keep the following terms in mind as you read:

    ClusterIP: The IP address assigned to a Service. In other documents, it may be called the "Cluster IP". This address is stable for the lifetime of the Service, as discussed in the Services section in this topic.

    Pod IP: The IP address assigned to a given Pod. This is ephemeral, as discussed in the Pods section in this topic.

    Node IP: The IP address assigned to a given node.

    Additionally you may have a look at the exposing your service documentation which may give you even more insight.

    And to support the fact that you got your node's IP - GKE uses an IP masquerading:

    IP masquerading is a form of network address translation (NAT) used to perform many-to-one IP address translations, which allows multiple clients to access a destination using a single IP address. A GKE cluster uses IP masquerading so that destinations outside of the cluster only receive packets from node IP addresses instead of Pod IP addresses.