1 | # Javascript Kubernetes Client information
|
2 |
|
3 | [![Build Status](https://travis-ci.org/kubernetes-client/javascript.svg?branch=master)](https://travis-ci.org/kubernetes-client/javascript)
|
4 | [![Client Capabilities](https://img.shields.io/badge/Kubernetes%20client-Silver-blue.svg?style=flat&colorB=C0C0C0&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 |
|
7 |
|
8 | The Javascript clients for Kubernetes is implemented in
|
9 | [typescript](https://typescriptlang.org), but can be called from either
|
10 | Javascript or Typescript.
|
11 |
|
12 | For now, the client is implemented for server-side use with node
|
13 | using the `request` library.
|
14 |
|
15 | There are future plans to also build a jQuery compatible library but
|
16 | for now, all of the examples and instructions assume the node client.
|
17 |
|
18 | # Installation
|
19 | ```console
|
20 | npm install @kubernetes/client-node
|
21 | ```
|
22 |
|
23 | # Example code
|
24 |
|
25 | ## List all pods
|
26 | ```javascript
|
27 | const k8s = require('@kubernetes/client-node');
|
28 |
|
29 |
|
30 | const kc = new k8s.KubeConfig();
|
31 | kc.loadFromDefault();
|
32 |
|
33 | const k8sApi = kc.makeApiClient(k8s.Core_v1Api);
|
34 |
|
35 | k8sApi.listNamespacedPod('default')
|
36 | .then((res) => {
|
37 | console.log(res.body);
|
38 | });
|
39 | ```
|
40 |
|
41 | ## Create a new namespace
|
42 | ```javascript
|
43 | const k8s = require('@kubernetes/client-node');
|
44 |
|
45 | const kc = new k8s.KubeConfig();
|
46 | kc.loadFromDefault();
|
47 |
|
48 | const k8sApi = kc.makeApiClient(k8s.Core_v1Api);
|
49 |
|
50 | var namespace = {
|
51 | metadata: {
|
52 | name: 'test'
|
53 | }
|
54 | };
|
55 |
|
56 | k8sApi.createNamespace(namespace).then(
|
57 | (response) => {
|
58 | console.log('Created namespace');
|
59 | console.log(response);
|
60 | k8sApi.readNamespace(namespace.metadata.name).then(
|
61 | (response) => {
|
62 | console.log(response);
|
63 | k8sApi.deleteNamespace(
|
64 | namespace.metadata.name, {} /* delete options */);
|
65 | });
|
66 | },
|
67 | (err) => {
|
68 | console.log('Error!: ' + err);
|
69 | }
|
70 | );
|
71 | ```
|
72 |
|
73 | # Additional Examples
|
74 | There are several more examples in the [examples](https://github.com/kubernetes-client/javascript/tree/master/examples) directory.
|
75 |
|
76 | # Development
|
77 |
|
78 | All dependencies of this project are expressed in its
|
79 | [`package.json` file](package.json). Before you start developing, ensure
|
80 | that you have [NPM](https://www.npmjs.com/) installed, then run:
|
81 |
|
82 | ```console
|
83 | npm install
|
84 | ```
|
85 |
|
86 | ## (re) Generating code
|
87 |
|
88 | ```console
|
89 | cd ../
|
90 | git clone https://github.com/kubernetes-client/gen
|
91 | cd javascript
|
92 | ../gen/openapi/typescript.sh src settings
|
93 | ```
|
94 |
|
95 | # Testing
|
96 |
|
97 | Tests are written using the [Chai](http://chaijs.com/) library. See
|
98 | [`config_test.ts`](./src/config_test.ts) for an example.
|
99 |
|
100 | To run tests, execute the following:
|
101 |
|
102 | ```console
|
103 | npm test
|
104 | ```
|
105 |
|
106 | ## Contributing
|
107 |
|
108 | Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.
|