在专用网络中使用 IP 伪装的 Kubernetes 流量
Kubernetes traffic with IP masquerading within private network
我希望我在 Kubernetes 中的 Pods 连接到集群外的其他进程 但 在同一 VPC 内(在 VM 或外部 BGP 传播网络上)。由于我 运行 在 GCP 上连接集群,来自 Kubernetes 集群的传出流量可以使用 Cloud NAT 进行 NAT 以用于外部流量,但同一 VPC 内的流量不会进行 NAT。
我可以简单地连接到私有 IP,但是对于一些目标进程有一些源 IP 过滤。它们不是由我自己维护的,需要 运行 在 VM 或其他网络上,我正在尝试查看是否有任何方法可以伪装离开 Kubernetes 集群的流量,即使在同一 VPC 中也是如此。我想过可能以某种方式将静态 IP 分配给 Pod / Statefulset,但这似乎很困难(即使以某种方式可能,弯曲 Kubernetes 网络似乎也不正确)。
我可以做些什么来处理来自 Kubernetes 的流量需求吗?或者我应该在 Kubernetes 集群之外单独创建一个 NAT,并通过它路由流量?
我认为更好的选择是配置 Internal TCP/UDP Load Balancing。
Internal TCP/UDP Load Balancing makes your cluster's services accessible to applications outside of your cluster that use the same VPC network and are located in the same Google Cloud region. For example, suppose you have a cluster in the us-west1 region and you need to make one of its services accessible to Compute Engine VM instances running in that region on the same VPC network.
内部负载平衡器确实是解决此问题的正确解决方案。
尽管在撰写本文时这不是 GA 版本(处于 Beta 阶段),但我继续使用 Kubernetes 服务注释,如所述https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balancing
以上文档的确切摘录 [ref]:
apiVersion: v1
kind: Service
metadata:
name: ilb-service
annotations:
cloud.google.com/load-balancer-type: "Internal"
labels:
app: hello
spec:
type: LoadBalancer
selector:
app: hello
ports:
- port: 80
targetPort: 8080
protocol: TCP
这意味着配置之间没有杂耍,我可以简单地依靠 Kubernetes 配置来启动 ILB。
为了记录,我还在 spec
下直接添加了 loadBalancerIP: 10.0.0.55
属性,它允许定义 ILB 使用的 IP(提供相关的 IP 范围匹配)[ref]。
我希望我在 Kubernetes 中的 Pods 连接到集群外的其他进程 但 在同一 VPC 内(在 VM 或外部 BGP 传播网络上)。由于我 运行 在 GCP 上连接集群,来自 Kubernetes 集群的传出流量可以使用 Cloud NAT 进行 NAT 以用于外部流量,但同一 VPC 内的流量不会进行 NAT。
我可以简单地连接到私有 IP,但是对于一些目标进程有一些源 IP 过滤。它们不是由我自己维护的,需要 运行 在 VM 或其他网络上,我正在尝试查看是否有任何方法可以伪装离开 Kubernetes 集群的流量,即使在同一 VPC 中也是如此。我想过可能以某种方式将静态 IP 分配给 Pod / Statefulset,但这似乎很困难(即使以某种方式可能,弯曲 Kubernetes 网络似乎也不正确)。
我可以做些什么来处理来自 Kubernetes 的流量需求吗?或者我应该在 Kubernetes 集群之外单独创建一个 NAT,并通过它路由流量?
我认为更好的选择是配置 Internal TCP/UDP Load Balancing。
Internal TCP/UDP Load Balancing makes your cluster's services accessible to applications outside of your cluster that use the same VPC network and are located in the same Google Cloud region. For example, suppose you have a cluster in the us-west1 region and you need to make one of its services accessible to Compute Engine VM instances running in that region on the same VPC network.
内部负载平衡器确实是解决此问题的正确解决方案。
尽管在撰写本文时这不是 GA 版本(处于 Beta 阶段),但我继续使用 Kubernetes 服务注释,如所述https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balancing
以上文档的确切摘录 [ref]:
apiVersion: v1
kind: Service
metadata:
name: ilb-service
annotations:
cloud.google.com/load-balancer-type: "Internal"
labels:
app: hello
spec:
type: LoadBalancer
selector:
app: hello
ports:
- port: 80
targetPort: 8080
protocol: TCP
这意味着配置之间没有杂耍,我可以简单地依靠 Kubernetes 配置来启动 ILB。
为了记录,我还在 spec
下直接添加了 loadBalancerIP: 10.0.0.55
属性,它允许定义 ILB 使用的 IP(提供相关的 IP 范围匹配)[ref]。