在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):godaddy/kubernetes-client开源软件地址(OpenSource Url):https://github.com/godaddy/kubernetes-client开源编程语言(OpenSource Language):JavaScript 92.5%开源软件介绍(OpenSource Introduction):kubernetes-clientSimplified Kubernetes API client for Node.js. InstallationInstall via npm:
Initializingkubernetes-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 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.setCurrentContext('dev') You can also elide the 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 usagekubernetes-client translates Path Item Objects [1] (e.g.,
So, to fetch all Namespaces: const namespaces = await client.api.v1.namespaces.get() kubernetes-client translates Path Templating [2] (e.g.,
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 Documentationkubernetes-client generates documentation for the included specifications: TypeScriptkubernetes-client includes a typings declartion file for Kubernetes
API 1.13 and a complimentry 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 Examplesexamples/ has snippets for using kubernetes-client:
ContributingSee the kubernetes-client Issues if you're interested in helping out; and look over the CONTRIBUTING.md before submitting new Issues and Pull Requests. TestingRun the unit tests:
The integration tests use the
Run integration tests with the
ReferencesLicense |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论