GCP 集群 ip 地址与请求的 remoteAddr 不同

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

我在 Google Cloud Platform Kubernetes public 集群中有一个节点。当我从我的应用程序向外部网站发出 HTTP 请求时,该网站中的 nginx 显示的 IP 地址与我的 kubernetes 集群的 IP 地址不同。我不知道那个IP地址是从哪里来的。我没有在 GCP 中使用 NAT。

在提供答案之前,我将添加一些官方术语以阐明 GKE networking

让我们来看看一些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.

此外,您还可以查看 exposing your service 文档,这可能会给您带来更多见解。

并支持 - 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.