0.2.16 • Published 2 years ago

k8s-client v0.2.16

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

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);
});
0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

5 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago