k8s.fetch.client

0.6.0 • Public • Published

k8s-fetch-client

Kubernetes node client that uses r2 internally for requests to take advantage of fetch and keep the library file size low when running from the browser. The k8s-fetch-client is fully compatible with async/await syntax!

Being written to the Fetch API is a huge benefit for browser users. When running through browserify request is ~2M uncompressed and ~500K compressed. r2 is only 66K uncompressed and 16K compressed.

See https://github.com/mikeal/r2 for more details about r2.

Getting Started

Simply create a new instance of the client and call .connect to parse the given kubernetes cluster's api.

const k8sClient = require('k8s-fetch-client');
const client = new k8sClient({
    host: '0.0.0.0',
    port: '8443'
});

async function start() {
    await client.connect();

    const pods = client.apis.Core.pods.get();
}

start();

How it Works

The .connect function fetches api metadata from the given kubernetes cluster and builds up a series of convenience functions for you to use. All api groups and resources are scoped under client.apis. It determines the preferred API version for each group and then fetches additional information about each Resource in the group. It then builds a series of helpers based on the supported verbs.

Note: Currently the client does not build child resources, e.g. deployments/status will be ignored.

GET /apis/apps/v1beta2

...
{
      "name": "deployments",
      "singularName": "",
      "namespaced": true,
      "kind": "Deployment",
      "verbs": [
        "create",
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "update",
        "watch"
      ],
      "shortNames": [
        "deploy"
      ],
      "categories": [
        "all"
      ]
    }
},
...

That resource definition will result in the following convenience methods.

verb: create -> client.apis.apps.Deployment.create(payload)
verb: delete -> client.apis.apps.Deployment.delete(identifier)
verb: deleteCollection -> client.apis.apps.Deployment.delete()
verb: get -> client.apis.apps.Deployment.get(identifier)
verb: list -> client.apis.apps.Deployment.get()
verb: patch -> client.apis.apps.Deployment.patch(payload)
verb: update -> client.apis.apps.Deployment.update(payload)
verb: watch -> client.apis.apps.Deployment.watch()

The format is always: client.apis.${resource.name}.${resource.kind}

/k8s.fetch.client/

    Package Sidebar

    Install

    npm i k8s.fetch.client

    Weekly Downloads

    11

    Version

    0.6.0

    License

    GPL-3.0

    Unpacked Size

    464 kB

    Total Files

    25

    Last publish

    Collaborators

    • containershipbot
    • mikestoltz
    • nicktate
    • normanjoyner