Skip to content

h-r-k-matsumoto/cloud-function-gke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloud Functions for GKE

This is an example of calling Kubernetes(GKE) API from Cloud Functions.

This example used Javascript Kubernetes Client

Feature

  • Display a list of pods in the default namespace.

Points

Cloud Functions probably doesn't support cloud_auth.

cloud_auth.ts is used gcloud .It is not available on Cloud Functions.

I responded as follows. Do not define authProvider . Because CloudAuth is executed, it will be an error.

    users: [
      {
        name: env.k8s.clusterFullName,
        user: {
          token: token,
        }
      }
    ]

user.token : Google API Authentication token.
The token is obtained using the Google Auth Library.

async function getToken() {
  let authResult = await auth.getClient({ scopes: 'https://www.googleapis.com/auth/cloud-platform' });
  let accessToken = await authResult.getAccessToken().catch((err) => {
    throw err;
  })
  return accessToken.token
}

Deploy

gcloud beta functions deploy kubefunc --entry-point ctl --trigger-http --project=${project-id} --env-vars-file .env.yaml --memory=128MB --runtime=nodejs8

About

Kubernetes api call by Cloud Functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published