项目作者: h-r-k-matsumoto

项目描述 :
Kubernetes api call by Cloud Functions.
高级语言: JavaScript
项目地址: git://github.com/h-r-k-matsumoto/cloud-function-gke.git
创建时间: 2019-04-23T09:40:10Z
项目社区:https://github.com/h-r-k-matsumoto/cloud-function-gke

开源协议:Apache License 2.0

下载


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.

  1. users: [
  2. {
  3. name: env.k8s.clusterFullName,
  4. user: {
  5. token: token,
  6. }
  7. }
  8. ]

user.token : Google API Authentication token.

The token is obtained using the Google Auth Library.

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

Deploy

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