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 🙏

© 2024 – Pkg Stats / Ryan Hefner

k8s-client

v0.2.16

Published

Kubernetes client for Node.js

Downloads

34

Readme

k8s client

Kubernetes client for Node.js.

This package is under active development. Feel free to suggest new features!

var Client = require('k8s-client');

var client = new Client({
  host: '127.0.0.1:8080'
  });

client.pods.getBySelector({ app: 'hello-world' }, function(err, pods){
  console.log(pods);
});

Installation

$ npm install --save k8s-client

Features

  • Manage all Kubernetes objects via the API.
  • Get objects by label selectors.
  • Scale replication controllers.
  • Delete replication controllers with all pods.
  • Supports token-based and client certificate authentication.

Get objects

To get objects, create a client object and use a collections' get method.

...
// get all pods
client.pods.get(function(err, pods){
  console.log(pods);
});

// get a single pod
client.pods.get('pod id', function(err, pod){
  console.log(pod);
});

// get pods by label selector
client.pods.getBySelector({ app: 'hello-world' }, function(err, pods){
  console.log(pods);
});

Authentication

To authenticate into a Kubernetes API, use the token, client certificate, or username/password options.

Token Authentication:

var Client = require('k8s-client');

var client = new Client({
  protocol: 'https',
  host: '127.0.0.1:443',
  token: 'thisismytoken'
  });

...

Certificate Authentication:

var Client = require('k8s-client');

var client = new Client({
  protocol: 'https',
  host: '127.0.0.1:443',
  clientKey: fs.readFileSync('tls/k8s-client.key'),
  clientCert: fs.readFileSync('tls/k8s-client.crt'),
  caCert: fs.readFileSync('tls/k8s-ca.crt')
  });

...

Basic Authentication:

var Client = require('k8s-client');

var client = new Client({
  url: 'https://127.0.0.1:443',
  username: 'jdoe',
  password: '1234'
  });

...

Creating Objects

To create an object user, the collection's create method.

...

var RC_MANIFEST = {
  kind: 'ReplicationController',
  apiVersion: 'v1',
  metadata: {
    name: 'nginx-rc',
    ...
  }
}

client.replicationControllers.create(RC_MANIFEST, function(err, rc){
  console.log('created nginx replication controller', rc)
});

Scaling

To scale a replication controller, call the scale or scaleAndWait methods.

...

// scale a replication controller without waiting
client.replicationControllers.scale('my-rc', 10, function(err, rc){
  console.log('scaled rc', rc);
});

// scale a replication controller and wait for all pods to report Ready
client.replicationControllers.scaleAndWait('my-rc', 10, function(err, rc){
  console.log('scaled rc', rc);
});

Deleting objects

To delete objects, call the delete method on the collection.

...

// delete a pod
client.pod.delete('my-pod', function(err, pod){
  console.log('deleted pod', pod);
  });

// delete a replication controller and it's pods
client.replicationControllers.delete('my-rc', function(err, rc){
  console.log('deleted rc with pods', rc);
});

// delete all replication controllers for app: test
client.replicationControllers.deleteBySelector({ app: 'test' }, function(err, rcs){
  console.log('deleted all test rcs', rcs);
});