Giter VIP home page Giter VIP logo

kubernetes-client's Introduction

kubernetes-client

Build Status Greenkeeper badge

Simplified Kubernetes API client for Node.js.

For the v4.X documentation, go HERE.

Installation

Install via npm:

npm i kubernetes-client --save

Initializing

kubernetes-client generates a Kubernetes API client at runtime based on a Swagger / OpenAPI specification. You can generate a client using specifications included with kubernetes-client:

const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config;
const client = new Client({ config: config.fromKubeconfig(), version: '1.9' });

or from a file:

const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config;
const spec = require('./swagger.json');
const client = new Client({ config: config.fromKubeconfig(), spec});

or from the /swagger.json endpoint on your kube-apiserver:

const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config;
const client = new Client({ config: config.fromKubeconfig() });
await client.loadSpec();

Basic usage

kubernetes-client translates Path Item Objects [1] (e.g., /api/v1/namespaces) to object chains ending in HTTP methods (e.g., api.v1.namespaces.get).

So, to fetch all Namesapces:

const namespaces = await client.api.v1.namespaces.get();

kubernetes-client translates Path Templating [2] (e.g., /apis/apps/v1/namespaces/{namespace}/deployments) to function calls (e.g., apis.apps.v1.namespaces('default').deployments).

So, to create a new Deployment in the default Namespace:

const deploymentManifest = require('./nginx-deployment.json')
const create = await client.apis.apps.v1.namespaces('default').deployments.post({ body: deploymentManifest });

and then fetch your newly created Deployment:

const deployment = await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).get();

and finally, remove the Deployment:

await await client.apis.apps.v1.namespaces('default').deployments(deploymentManifest.metadata.name).delete();

kubernetes-client supports .delete, .get, .patch, .post, and .put.

Documentation

kubernetes-client generates documentation for the included specifications:

More examples

examples/ has snippets for using kubernetes-client:

Contributing

See the kubernetes-client Issues if you're interested in helping out; and look over the CONTRIBUTING.md before submitting new Issues and Pull Requests.

Testing

kubernetes-client includes unit tests and integration tests. Minikube is a tool that makes it easy to run integration tests locally.

Run the unit tests:

$ npm test

The integration tests use a running Kubernetes server. You specify the Kubernetes server context via the CONTEXT environment variable. For example, run the integration tests with the minikube context:

$ CONTEXT=minikube npm run test-integration

More Documentation

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.