我正在尝试从NodeJS访问Kubernetes API.在没有kubectl或gcloud命令行工具可用的环境中运行.使用 github/kubernetes-client/javascript 客户端SDK.问题是如何验证和访问远程群集.对于在GCP中运行的K8,我需要它.
I'm trying to access Kubernetes APIs from NodeJS. Running in environment where no kubectl or gcloud command line tools are available. Using github/kubernetes-client/javascript client side SDK. The question is how to authenticate and access the remote cluster. I need this for K8s running in GCP.
换句话说,尝试执行"gcloud容器群集获取凭据"的操作,但是没有"gcloud" cli.
In other words trying to do what "gcloud container clusters get-credentials" does, but without "gcloud" cli.
推荐答案我认为您可以使用NodeJS调用Kubernetes API. rel ="nofollow noreferrer"> kubernetes-client 由 GoDaddy 推广. Kubernetes-client的Kubernetes-client简化了如何调整Kubernetes API接口的方法.
I think that you can invoke Kubernetes API from NodeJS using this kubernetes-client promoted by GoDaddy. Kubernetes-client for NodeJS simplifies a way how to adjust an interface to Kubernetes API.
下面的示例演示了一种方法,该方法如何使用小片段提取默认Kubernetes Namespace中的所有Deployments:
Below example demonstrates a way how to use a small snippet to extract all the Deployments in the default Kubernetes Namespace:
const Client = require('kubernetes-client').Client; const config = require('kubernetes-client').config; const client = new Client({ config: config.fromKubeconfig(), version: '1.9' }); const deployments = await client.api.v1.namespaces('default').deployments.get();此处,您可以找到更多使用kubernetes-client的代码段
Here you can find more snippets for using kubernetes-client.
更多推荐
使用REST API访问Kubernetes API
发布评论