• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

godaddy/kubernetes-client: Simplified Kubernetes API client for Node.js.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

godaddy/kubernetes-client

开源软件地址(OpenSource Url):

https://github.com/godaddy/kubernetes-client

开源编程语言(OpenSource Language):

JavaScript 92.5%

开源软件介绍(OpenSource Introduction):

kubernetes-client

Join Slack Build Status Greenkeeper badge

Simplified Kubernetes API client for Node.js.

Installation

Install via npm:

npm i kubernetes-client --save

Initializing

kubernetes-client generates a Kubernetes API client at runtime based on a Swagger / OpenAPI specification. You can generate a client using the cluster's kubeconfig file and that cluster's API specification.

To create the config required to make a client, you can either:

let kubernetes-client configure automatically by trying the KUBECONFIG environment variable first, then ~/.kube/config, then an in-cluster service account, and lastly settling on a default proxy configuration:

const client = new Client({ version: '1.13' })

provide your own path to a file:

const { KubeConfig } = require('kubernetes-client')
const kubeconfig = new KubeConfig()
kubeconfig.loadFromFile('~/some/path')
const Request = require('kubernetes-client/backends/request')

const backend = new Request({ kubeconfig })
const client = new Client({ backend, version: '1.13' })

provide a configuration object from memory:

// Should match the kubeconfig file format exactly
const config = {
  apiVersion: 'v1',
  clusters: [],
  contexts: [],
  'current-context': '',
  kind: 'Config',
  users: []
}
const { KubeConfig } = require('kubernetes-client')
const kubeconfig = new KubeConfig()
kubeconfig.loadFromString(JSON.stringify(config))

const Request = require('kubernetes-client/backends/request')
const backend = new Request({ kubeconfig })
const client = new Client({ backend, version: '1.13' })

and you can also specify the context by setting it in the kubeconfig object:

kubeconfig.setCurrentContext('dev')

You can also elide the .version and pass an OpenAPI specification:

const spec = require('./swagger.json')
const client = new Client({ spec })

or load a specification dynamically from the kube-apiserver:

const client = new Client()
await client.loadSpec()

See Examples for more configuration examples.

Basic usage

kubernetes-client translates Path Item Objects [1] (e.g., /api/v1/namespaces) to object chains ending in HTTP methods (e.g., api.v1.namespaces.get).

So, to fetch all Namespaces:

const namespaces = await client.api.v1.namespaces.get()

kubernetes-client translates Path Templating [2] (e.g., /apis/apps/v1/namespaces/{namespace}/deployments) to function calls (e.g., apis.apps.v1.namespaces('default').deployments).

So, to create a new Deployment in the default Namespace:

const deploymentManifest = require('./nginx-deployment.json')
const create = await client.apis.apps.v1.namespaces('default').deployments.post({ body: deploymentManifest })

and then fetch your newly created Deployment:

const deployment = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).get()

and finally, remove the Deployment:

await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).delete()

kubernetes-client supports .delete, .get, .patch, .post, and .put.

Documentation

kubernetes-client generates documentation for the included specifications:

TypeScript

kubernetes-client includes a typings declartion file for Kubernetes API 1.13 and a complimentry Client1_13 class:

import * as ApiClient from 'kubernetes-client';

const Client = ApiClient.Client1_13;
const client = new Client({ version: '1.13' });

When using TypeScript, kubernetes-client does not support dynamically generating a client via .loadSpec().

Examples

examples/ has snippets for using kubernetes-client:

Contributing

See the kubernetes-client Issues if you're interested in helping out; and look over the CONTRIBUTING.md before submitting new Issues and Pull Requests.

Testing

Run the unit tests:

npm test

The integration tests use the current-context in your kubeconfig file. Run the integration tests:

npm run test-integration

Run integration tests with the @kubernetes/client-node backend:

KUBERNETES_CLIENT_BACKEND=client-node npm run test-integration

References

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap