Skip to content

Kubernetes api client with support for async/await, watch for resources and auto conf

Notifications You must be signed in to change notification settings

mcasimir/kubernetes-api-client

Repository files navigation

Kubernetes Api Client for Node.js

Install

npm install --save kubernetes-api-client

Usage

const KubernetesApiClient = require('kubernetes-api-client');

const k8s = new KubernetesApiClient();

async function main() {
  const {items} = await k8s.get('api/v1/namespaces');

  console.info('Available namespaces:');

  for (const ns of items) {
    console.info('-', ns.metadata.name);
  }

  console.info('Waiting for namespace events:');

  const nsId = `test-ns-${Date.now()}`;
  setTimeout(function() {
    k8s.post('api/v1/namespaces', {
      metadata: {
        name: nsId
      }
    });
  }, 3000);

  setTimeout(function() {
    k8s.delete(`api/v1/namespaces/${nsId}`);
  }, 6000);

  await k8s.watch('v1/namespaces', function({type, object: ns}) {
    if (type === 'ADDED') {
      console.info('Namespace added:', ns.metadata.name);
    }

    if (type === 'MODIFIED') {
      console.info('Namespace modified:', ns.metadata.name);
    }

    if (type === 'DELETED') {
      console.info('Namespace deleted:', ns.metadata.name);
    }
  });

}

main().catch(function(err) {
  console.error(err);
  process.exit(1);
});

Getting Started

About

Kubernetes api client with support for async/await, watch for resources and auto conf

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published