使用REST API访问Kubernetes API

编程入门 行业动态 更新时间:2024-10-07 18:30:53
本文介绍了使用REST API访问Kubernetes API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从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

本文发布于:2023-11-28 11:21:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642195.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:REST   API   Kubernetes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!