npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

emaildanwilson-node-kubernetes-client

v0.2.3

Published

Kubernetes client of Node.js

Readme

Google Kubernetes client

Node.js client library for Google's Kubernetes API (https://github.com/GoogleCloudPlatform/kubernetes) You can use this library to call a Kubernetes API hosted in a Kubernetes master node using Node.js.

Install:

npm install emaildanwilson-node-kubernetes-client

Current endpoint support includes:

  • events
  • endpoints
  • namespaces
  • pods
  • minions
  • services
  • replicationControllers
  • nodes
  • proxyMinions
  • proxyNodes
  • proxyPods
  • proxyServices
  • watchPods

Interaction is accomplished via client.<endpoint>.<method>. (see examples below)

Usage

Create client

Authentication can be done via either token or login. If, however, the token expires, the login info will be used to acquire a new token.

var Client = require('node-kubernetes-client');

var client = new Client({
    host:  'xx.xx.xx.xx',
    protocol: 'https',
    version: 'v1beta2',
    token: 'XYZ'
});

Optional params:

Some optional params also exist on initialising the client.

{
    namespace:  'someNamespace', // filter all client requests by a namespace - default is no namespace
    timeout: 20000 // A timeout (in ms) for requests to k8 apis
    reqOptions: {} // array of options used to override the npm request module for this client proxy, auth, etc.
}

Getting from pods

Paging is accomplished automatically. For example, a request for pods will return all pods, not just those returned on the first page.

For example, to get all pods:

client.pods.get(function (err, pods) {
    console.log('pods:', pods);
});

Retrieving from Custom Collections

Retrieving from custom k8 collections is enabled by using the createCollection functionality.

For example, to create a custom collection called "routes":

var schema = null, //optional param
innerCollections = null, // optional param
options = { apiPrefix : 'api2' }; // optionally set a per-collection api prefix
client.routes = client.createCollection('routes', schema, innerCollections, options);
// then use the routes collection like any other

Custom Collection for k8s deployments

client = new Client({
  host:  'xx.xx.xx.xx',
  protocol: 'https',
  version: 'extensions/v1beta1',
  token: 'XYZ',
  namespace:  'mynamespace',
  reqOptions: {proxy: configLocation.proxy || null},
  timeout: 20000 
});
// add deployments to the api
client.deployments = client.createCollection('deployments', null, null, { apiPrefix : 'apis' });

var deploymentJSON = {
          "apiVersion": "extensions/v1beta1",
          "kind": "Deployment",
          ...
          }

// then use the deployments collection like any other
client.deployments.get(deploymentJSON.metadata.name, function (err, data) {
  if (err && err.statusCode != 404) {
    //something is wrong, bail
    console.log("error checking for deployment:", err);
    return;
  } else if (err && err.statusCode == 404) {
    //create if not found
    client.deployments.create(deploymentJSON, function (err, data) {
      if (err) {
        console.log("error updating deployment:", err);
        return;
      } else {
        console.log("deployment created:", deploymentJSON.metadata.name);
        return;
      }
    });
  } else {
    //update since it did not exist
    client.deployments.update(deploymentJSON.metadata.name, deploymentJSON, function (err, data) {
      if (err) {
        console.log("error updating deployment:", err);
        return;
      }
      console.log("deployment updated:", deploymentJSON.metadata.name);
      return;
    }); 
  }
});

How to run the test cases

install mocha

  npm install mocha

run testcase

  mocha test-pods.js

The results will be output to test/results/ directory with formatted JSON.

Roadmap

See issues.

Others

You may interested in kubernetes client library using other programming languanges, please check the below link (https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/client-libraries.md)