如何使用外部IP保护来自到达ClusterIP服务的流量的源IP?

5 network-programming google-compute-engine kubernetes google-kubernetes-engine

我目前有一个看起来像这样的服务:

apiVersion: v1
kind: Service
metadata:
  name: httpd
spec:
  ports:
    - port: 80
      targetPort: 80
      name: http
      protocol: TCP
    - port: 443
      targetPort: 443
      name: https
      protocol: TCP
  selector:
    app: httpd
  externalIPs:
    - 10.128.0.2  # VM's internal IP
Run Code Online (Sandbox Code Playgroud)

我可以从绑定到VM的外部IP获得良好的流量,但所有请求都由HTTP与源IP接收10.104.0.1,这绝对是内部IP - 即使我从群集外部连接到VM的外部IP也是如此.

如何在不设置负载均衡器或入口的情况下获取请求的真实源IP?

Sym*_*ric 1

这并不容易实现——由于 kube-proxy 的工作方式,您的流量可以在到达支持您的服务的 pod 之前在节点之间转发。

您可以使用一些 beta 注释来解决这个问题,特别是service.beta.kubernetes.io/external-traffic: OnlyLocal.

文档中的更多信息,请参见: https: //kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typeloadbalancer

但这并不能满足您不需要LoadBalancer的额外要求。您能详细说明为什么您不想使用 LoadBalancer 吗?