Using Gmail API from an app running inside container

9/10/2018

I'm wondering how to use Gmail API from an app running inside the container (of GKE)?

For my local development, I can run the example https://developers.google.com/gmail/api/quickstart/go to get a code then the program saves a token, send an email successfully (I've changed the scope, the example only has read-only)

But I don't have the interactive terminal for the container running in K8S, so I set the credentials and token as env var for the process running inside the container (my program consumes the env var, and local testing sent the email successfully), it doesn't seem to be able to contact Gmail API.

The exact error is : Post https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json&prettyPrint=false: dial tcp: i/o timeout"

So I have two question here:

  1. why is container in GKE is unable to contact www.googleapis.com
  2. What's the best way of handling gmail api inside a container? Am I missing steps to setup google APIs?

Thanks, Bill

-- Bill Chung
containers
gmail-api
go
google-kubernetes-engine

1 Answer

9/10/2018

It appears to be one of the dns pod exited that caused dns lookup to hang and resulted in tcp i/o timeout:

kube-dns-5dcfcbf5fb-w2vjc 0/4 ExitCode:0 23 3d

after fixing the pod, now the application is able to send email thru gmail APIs.

-- Bill Chung
Source: StackOverflow