GKE:pods 与推送订阅者之间的 Pubsub 消息

GKE: Pubsub messages between pods with push subscribers

我正在使用多个 pods 的 GKE 部署,我需要在 pods 之间发送和接收消息。我想使用 pubsub push subscribers.

我发现推送需要为订阅者配置 https 访问 pods。

In order to receive push messages, you need a publicly accessible HTTPS server to handle POST requests. The server must present a valid SSL certificate signed by a certificate authority and routable by DNS. You also need to validate that you own the domain (or have equivalent access to the endpoint).

这真的是必需的还是有一些解决方法。这是否意味着我应该使用 Ingress 公开每个订阅者 pod,即使是内部通信?

如果您只需要 pods 在某个端口上公开(用于 pod 到 pod 通信),那么您只需要通过针对该端口(在您的情况下为端口 443)的服务公开每个 pod ).

例如,通过使用以下 YAML,您可以创建一个以 pod 上的端口为目标的服务:

apiVersion: v1
kind: Service
metadata:
  name: my-pod
  labels:
    run: my--pod
spec:
  ports:
  - port: 443
    targetPort: 443
    protocol: TCP
  selector:
    run: my-pod

以上内容将创建一个服务,该服务以带有 run: my-pod 标签的任何 Pod 上的 TCP 端口 443 为目标。在文件中,targetPort 是容器(在 pod 内)接受流量的端口,port 是抽象的服务端口,可以是其他 pods 用来访问的任何端口服务)。

编辑:

但是,如果您需要 pods 能够与 Pub-Sub API 进行通信,则需要具有与外部通信的能力,因此建议使用 ingress。

回应您在评论中提出的问题 "I wonder why Google needs to access Kubernetes with public HTTPS instead on some internal request"- 原因是这不是内部请求。 Pub-Sub API 位于您的 project/network 之外,因此数据会跨其他网络传输。为了安全起见,它需要加密——这就是使用 HTTPS 的原因。