- Notifications
You must be signed in to change notification settings - Fork552
kubernetes-client/javascript
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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.
npm install @kubernetes/client-node
constk8s=require('@kubernetes/client-node');constkc=newk8s.KubeConfig();kc.loadFromDefault();constk8sApi=kc.makeApiClient(k8s.CoreV1Api);k8sApi.listNamespacedPod({namespace:'default'}).then((res)=>{console.log(res);});
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);},);
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);...
There are several more JS and TS examples in theexamples directory.
Documentation for the library is split into two resources:
- TheKubernetes API Reference is the source-of-truth for all Kubernetes client libraries, including this one. We suggest starting here!
- The Typedoc autogenerated docs can be viewedonline and can also be built locally (see below)
Prior to the0.13.0
release, release versions did not track Kubernetes versions. Starting with the0.13.0
release, 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 version | older versions | 1.28 | 1.29 | 1.30 | 1.31 | 1.32 | 1.33 |
---|---|---|---|---|---|---|---|
0.19.x | - | ✓ | x | x | x | x | x |
0.20.x | - | + | ✓ | x | x | x | x |
0.21.x | - | + | + | ✓ | x | x | x |
0.22.x | - | + | + | + | ✓ | x | x |
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.
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 as
Impersonate-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.
All dependencies of this project are expressed in itspackage.json
file. Before you start developing, ensurethat you haveNPM installed, then run:
npm install
npm run generate
Documentation is generated via typedoc:
npm run docs
To view the generated documentation, opendocs/index.html
Runnpm run format
or install an editor plugin likehttps://github.com/prettier/prettier-vscode andhttps://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
Runnpm run lint
or install an editor plugin.
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
Please seeCONTRIBUTING.md for instructions on how to contribute.
About
JavaScript client
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.