Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JavaScript client

License

NotificationsYou must be signed in to change notification settings

kubernetes-client/javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build StatusClient CapabilitiesClient Support LevelBuild and Deploy Docs

The Javascript clients for Kubernetes is implemented intypescript, but can be called from eitherJavascript or Typescript. The client is implemented for server-side use with Node.

Installation

npm install @kubernetes/client-node

Example code

List all pods

constk8s=require('@kubernetes/client-node');constkc=newk8s.KubeConfig();kc.loadFromDefault();constk8sApi=kc.makeApiClient(k8s.CoreV1Api);k8sApi.listNamespacedPod({namespace:'default'}).then((res)=>{console.log(res);});

Create a new namespace

constk8s=require('@kubernetes/client-node');constkc=newk8s.KubeConfig();kc.loadFromDefault();constk8sApi=kc.makeApiClient(k8s.CoreV1Api);varnamespace={metadata:{name:'test',},};k8sApi.createNamespace({body:namespace}).then((response)=>{console.log('Created namespace');console.log(response);k8sApi.readNamespace(namespace.metadata.name).then((response)=>{console.log(response);k8sApi.deleteNamespace(namespace.metadata.name,{}/* delete options */);});},(err)=>{console.log('Error!: '+err);},);

Create a cluster configuration programatically

constk8s=require('@kubernetes/client-node');constcluster={name:'my-server',server:'http://server.com',};constuser={name:'my-user',password:'some-password',};constcontext={name:'my-context',user:user.name,cluster:cluster.name,};constkc=newk8s.KubeConfig();kc.loadFromOptions({clusters:[cluster],users:[user],contexts:[context],currentContext:context.name,});constk8sApi=kc.makeApiClient(k8s.CoreV1Api);...

Additional Examples and Documentation

There are several more JS and TS examples in theexamples directory.

Documentation for the library is split into two resources:

  1. TheKubernetes API Reference is the source-of-truth for all Kubernetes client libraries, including this one. We suggest starting here!
  2. The Typedoc autogenerated docs can be viewedonline and can also be built locally (see below)

Compatibility

Prior to the0.13.0 release, release versions did not track Kubernetes versions. Starting with the0.13.0release, we will increment the minor version whenever we update the minor Kubernetes API version(e.g.1.19.x) that this library is generated from.

We switched fromrequest tofetch as the HTTP(S) backend for the1.0.0 release.

Generally speaking newer clients will work with older Kubernetes, but compatability isn't 100% guaranteed.

client versionolder versions1.281.291.301.311.321.33
0.19.x-xxxxx
0.20.x-+xxxx
0.21.x-++xxx
0.22.x-+++xx
1.0.x-++++x
1.1.x-++++x
1.2.x-+++++

Key:

  • Exactly the same features / API objects in both javascript-client and the Kubernetesversion.
  • + javascript-client has features or api objects that may not be present in theKubernetes cluster, but everything they have in common will work.
  • - The Kubernetes cluster has features the javascript-client library can't use(additional API objects, etc).
  • x The Kubernetes cluster has no guarantees to support the API client ofthis version, as it only promisesn-2 version support. It is not tested,and operations using API versions that have been deprecated and removed inlater server versions won't function correctly.

Known Issues

  • Multiple kubeconfigs are not completely supported.Credentials are cached based on the kubeconfig username and these can collide across configs.Here is the relatedissue.

  • In scenarios where multiple headers with the same key are required in a request, such asImpersonate-Group, avoid usingfetch. Fetch will merge the values into a single header key, with the values as a single string vs a list of strings,Impersonate-Group: "group1,group2". The workaround is to use a low-level library such ashttps to make the request. Refer to issue#2474 for more details.

Development

All dependencies of this project are expressed in itspackage.json file. Before you start developing, ensurethat you haveNPM installed, then run:

npm install

(re) Generating code

npm run generate

Documentation

Documentation is generated via typedoc:

npm run docs

To view the generated documentation, opendocs/index.html

Formatting

Runnpm run format or install an editor plugin likehttps://github.com/prettier/prettier-vscode andhttps://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

Linting

Runnpm run lint or install an editor plugin.

Testing

Tests are written using thenode:test test runner andnode:assert assertion library. Seeconfig_test.ts for an example.

To run tests, execute the following:

npm test

Contributing

Please seeCONTRIBUTING.md for instructions on how to contribute.

About

JavaScript client

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp