GKE: Pubsub messages between pods with push subscribers

时间:2018-03-25 19:36:30

标签: google-cloud-platform google-cloud-pubsub google-kubernetes-engine

I am using GKE deployment with multiple pods and I need to send and receive messages between pods. I want to use pubsub push subscribers.

I found for push I need to configure https access for subscribers 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).

Is this really required or is there some workaround. Does it mean I should expose each subscriber pod with Ingress, even for internal communication?

2 个答案:

答案 0 :(得分:2)

如果您只需要在某个端口上暴露pod(用于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是抽象的服务端口,可以是其他pod用于访问服务的任何端口。

编辑:

但是,如果您需要pod可以与Pub-Sub API进行通信,则需要具备外部通信的能力,因此建议您进入。

回答您在评论中的问题“我想知道为什么Google需要使用公共HTTPS而不是某些内部请求来访问Kubernetes” - 原因是它不是内部请求。 Pub-Sub API位于项目/网络之外,因此数据通过其他网络传输。为了保证安全,需要加密 - 这就是使用HTTPS的原因。

答案 1 :(得分:0)

我还不能确定,但​​是根据GCP上的这篇文章,如果您可以通过提供正确的服务向Cloud Platform服务进行身份验证,则可以使用Pub / Sub Push机制在Kubernetes引擎上使用消息群集的帐户权限。

编辑:好的,这仅适用于基于拉的模型,但是基于拉的模型在任何一天的伸缩性都更好,您拥有更多的控制权:)