pubsub.NewClient method stuck on GKE golang

时间秒杀一切 提交于 2021-02-10 07:37:08

问题


I am developing a golang app that uses Google Pub/Sub client library. I am using Google container engine for deployment. I followed the following steps for deployment -

  1. Build golang binary using CGO_ENABLED=0 GOOS=linux go build -o bin/app app.go
  2. Build a docker image using dockerfile shown below.
  3. Create kubernetes deployment.

Dockerfile -

FROM scratch 
ADD bin/app /
CMD ["/app"]

The app starts fine and I can see some initial debug logs. However, when I try to instantiate a pub/sub client using client, err := pubsub.NewClient(ctx, projectId), the method call never returns. I do not see the log message printed right after this statement.

I have "Cloud Pub/Sub" permission enabled on my GKE cluster. Also, the app runs without any issues on my local machine.

What might be the issue?


回答1:


Okay so I finally found the problem and its solution. My image does not contain any SSL certificates which are required for the pub/sub client (and many other libraries of course) to communicate.

Adding my local machine's /etc/ssl/certs/ca-certificates.crt file to the docker image's /etc/ssl/certs/ location solved the problem.

This awesome post at codeship is where I learned this solution.



来源:https://stackoverflow.com/questions/46618942/pubsub-newclient-method-stuck-on-gke-golang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!