UNPKG

5.14 kBMarkdownView Raw
1# Javascript Kubernetes Client information
2
3[![Build Status](https://github.com/kubernetes-client/javascript/workflows/Kubernetes%20Javascript%20Client%20-%20Validation/badge.svg)](https://github.com/kubernetes-client/javascript/actions)
4[![Client Capabilities](https://img.shields.io/badge/Kubernetes%20client-Gold-blue.svg?style=flat&colorB=FFD700&colorA=306CE8)](http://bit.ly/kubernetes-client-capabilities-badge)
5[![Client Support Level](https://img.shields.io/badge/kubernetes%20client-beta-green.svg?style=flat&colorA=306CE8)](http://bit.ly/kubernetes-client-support-badge)
6
7The Javascript clients for Kubernetes is implemented in
8[typescript](https://typescriptlang.org), but can be called from either
9Javascript or Typescript.
10
11For now, the client is implemented for server-side use with node
12using the `request` library.
13
14There are future plans to also build a jQuery compatible library but
15for now, all of the examples and instructions assume the node client.
16
17# Installation
18
19```console
20npm install @kubernetes/client-node
21```
22
23# Example code
24
25## List all pods
26
27```javascript
28const k8s = require('@kubernetes/client-node');
29
30const kc = new k8s.KubeConfig();
31kc.loadFromDefault();
32
33const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
34
35k8sApi.listNamespacedPod('default').then((res) => {
36 console.log(res.body);
37});
38```
39
40## Create a new namespace
41
42```javascript
43const k8s = require('@kubernetes/client-node');
44
45const kc = new k8s.KubeConfig();
46kc.loadFromDefault();
47
48const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
49
50var namespace = {
51 metadata: {
52 name: 'test',
53 },
54};
55
56k8sApi.createNamespace(namespace).then(
57 (response) => {
58 console.log('Created namespace');
59 console.log(response);
60 k8sApi.readNamespace(namespace.metadata.name).then((response) => {
61 console.log(response);
62 k8sApi.deleteNamespace(namespace.metadata.name, {} /* delete options */);
63 });
64 },
65 (err) => {
66 console.log('Error!: ' + err);
67 },
68);
69```
70
71## Create a cluster configuration programatically
72```javascript
73const k8s = require('@kubernetes/client-node');
74
75const cluster = {
76 name: 'my-server',
77 server: 'http://server.com',
78};
79
80const user = {
81 name: 'my-user',
82 password: 'some-password',
83};
84
85const context = {
86 name: 'my-context',
87 user: user.name,
88 cluster: cluster.name,
89};
90
91const kc = new k8s.KubeConfig();
92kc.loadFromOptions({
93 clusters: [cluster],
94 users: [user],
95 contexts: [context],
96 currentContext: context.name,
97});
98const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
99...
100```
101
102# Additional Examples
103
104There are several more examples in the [examples](https://github.com/kubernetes-client/javascript/tree/master/examples) directory.
105
106# Compatibility
107
108Prior to the `0.13.0` release, release versions did not track Kubernetes versions. Starting with the `0.13.0`
109release, we will increment the minor version whenever we update the minor Kubernetes API version
110(e.g. `1.19.x`) that this library is generated from.
111
112Generally speaking newer clients will work with older Kubernetes, but compatability isn't 100% guaranteed.
113
114| client version | older versions | 1.18 | 1.19 | 1.20 |
115|----------------|----------------|------|------|------|
116| 0.12.x | - | ✓ | x | x |
117| 0.13.x | - | + | ✓ | x |
118| 0.14.x | - | + | + | ✓ |
119
120Key:
121
122* `✓` Exactly the same features / API objects in both javascript-client and the Kubernetes
123 version.
124* `+` javascript-client has features or api objects that may not be present in the
125 Kubernetes cluster, but everything they have in common will work.
126* `-` The Kubernetes cluster has features the javascript-client library can't use
127 (additional API objects, etc).
128* `x` The Kubernetes cluster has no guarantees to support the API client of
129 this version, as it only promises _n_-2 version support. It is not tested,
130 and operations using API versions that have been deprecated and removed in
131 later server versions won't function correctly.
132
133
134# Development
135
136All dependencies of this project are expressed in its
137[`package.json` file](package.json). Before you start developing, ensure
138that you have [NPM](https://www.npmjs.com/) installed, then run:
139
140```console
141npm install
142```
143
144## (re) Generating code
145
146```console
147npm run generate
148```
149
150## Documentation
151
152Documentation is generated via typedoc:
153
154```
155npm run docs
156```
157
158To view the generated documentation, open `docs/index.html`
159
160## Formatting
161
162Run `npm run format` or install an editor plugin like https://github.com/prettier/prettier-vscode and https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
163
164## Linting
165
166Run `npm run lint` or install an editor plugin like https://github.com/Microsoft/vscode-typescript-tslint-plugin
167
168# Testing
169
170Tests are written using the [Chai](http://chaijs.com/) library. See
171[`config_test.ts`](./src/config_test.ts) for an example.
172
173To run tests, execute the following:
174
175```console
176npm test
177```
178
179## Contributing
180
181Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.