问题
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 -
- Build golang binary using
CGO_ENABLED=0 GOOS=linux go build -o bin/app app.go
- Build a docker image using dockerfile shown below.
- 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