UNPKG

2.79 kBMarkdownView Raw
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
8The Javascript clients for Kubernetes is implemented in
9[typescript](https://typescriptlang.org), but can be called from either
10Javascript or Typescript.
11
12For now, the client is implemented for server-side use with node
13using the `request` library.
14
15There are future plans to also build a jQuery compatible library but
16for now, all of the examples and instructions assume the node client.
17
18# Installation
19```console
20npm install @kubernetes/client-node
21```
22
23# Example code
24
25## List all pods
26```javascript
27const k8s = require('@kubernetes/client-node');
28
29
30const kc = new k8s.KubeConfig();
31kc.loadFromDefault();
32
33const k8sApi = kc.makeApiClient(k8s.Core_v1Api);
34
35k8sApi.listNamespacedPod('default')
36 .then((res) => {
37 console.log(res.body);
38 });
39```
40
41## Create a new namespace
42```javascript
43const k8s = require('@kubernetes/client-node');
44
45const kc = new k8s.KubeConfig();
46kc.loadFromDefault();
47
48const k8sApi = kc.makeApiClient(k8s.Core_v1Api);
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(
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
74There are several more examples in the [examples](https://github.com/kubernetes-client/javascript/tree/master/examples) directory.
75
76# Development
77
78All dependencies of this project are expressed in its
79[`package.json` file](package.json). Before you start developing, ensure
80that you have [NPM](https://www.npmjs.com/) installed, then run:
81
82```console
83npm install
84```
85
86## (re) Generating code
87
88```console
89cd ../
90git clone https://github.com/kubernetes-client/gen
91cd javascript
92../gen/openapi/typescript.sh src settings
93```
94
95# Testing
96
97Tests are written using the [Chai](http://chaijs.com/) library. See
98[`config_test.ts`](./src/config_test.ts) for an example.
99
100To run tests, execute the following:
101
102```console
103npm test
104```
105
106## Contributing
107
108Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.