k8s.fetch.client
v0.6.0
Published
NodeJS K8s Client using R2 internally for requests.
Keywords
Readme
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/statuswill 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}
