Code Monkey home page Code Monkey logo

node-k8s-client's Introduction

Nodejs Kubernetes client

Node.js client library for Google's Kubernetes Kubectl And API

build

    git clone https://github.com/Goyoo/node-k8s-client.git
    npm install
    npm run build

#test for test please install minikube

    
    mocha test

Install:

    npm install k8s

Usage

Create client

var K8s = require('k8s')

// use kubectl

var kubectl = K8s.kubectl({
    endpoint:  'http://192.168.10.10:8080'
    , namespace: 'namespace'
    , binary: '/usr/local/bin/kubectl'
})

//use restful api
var kubeapi = K8s.api({
	endpoint: 'http://192.168.10.10:8080'
	, version: '/api/v1'
})

// Configure using kubeconfig
var kubeapi = K8s.api({
    kubeconfig: '/etc/cluster1.yaml'
    ,version: '/api/v1'
})

var kube = K8s.kubectl({
	binary: '/bin/kubectl'
	,kubeconfig: '/etc/cluster1.yaml'
	,version: '/api/v1'
});

Options

endpoint : URL for API

version : API Version

binary : Path to binary file

kubeconfig : Path to kubeconfig

:auth See below authentication section

:strictSSL If set to false, use of the API will not validate SSL certificate. Defualt is true.

Authentication

Authentication to REST API is done via the auth option. Currently supported authentication method types are username/password, token and client certificate. Presence of authentication details is checked in this order so if a token is specified as well as a client certificate then a token will be used.

Username/password:

{
  "auth": {
    "username": "admin",
    "password": "123123"
  }
}

Token:

{
  "auth": {
    "token": "hcc927ndkcka12"
  }
}

Client certificate:

{
  "auth": {
    "clientKey": fs.readFileSync('k8s-client-key.pem'),
    "clientCert": fs.readFileSync('k8s-client-cert.pem'),
    "caCert": fs.readFileSync('k8s-ca-crt.pem')
  }
}

kubeAPI

using callback

// method GET
kubeapi.get('namespaces/default/replicationcontrollers', function(err, data){})

// method POST
kubeapi.post('namespaces/default/replicationcontrollers', require('./rc/nginx-rc.json'), function(err, data){})
// method PUT
kubeapi.put('namespaces/default/replicationcontrollers/nginx', require('./rc/nginx-rc.json'), function(err, data){})
// method PATCH
kubeapi.patch('namespaces/default/replicationcontrollers/nginx', [{ op: 'replace', path: '/spec/replicas', value: 2 }], function(err, data){})
// method DELETE
kubeapi.delete('namespaces/default/replicationcontrollers/nginx', function(err, data){})

using promise

// method GET
kubeapi.get('namespaces/default/replicationcontrollers').then(function(data){}).catch(function(err){})
// method POST
kubeapi.post('namespaces/default/replicationcontrollers', require('./rc/nginx-rc.json')).then(function(data){}).catch(function(err){})
// method PUT
kubeapi.put('namespaces/default/replicationcontrollers/nginx', require('./rc/nginx-rc.json')).then(function(data){}).catch(function(err){})
// method PATCH
kubeapi.patch('namespaces/default/replicationcontrollers/nginx', [{ op: 'replace', path: '/spec/replicas', value: 2 }]).then(function(data){}).catch(function(err){})
// method DELETE
kubeapi.delete('namespaces/default/replicationcontrollers/nginx').then(function(data){}).catch(function(err){})

using async/await

!async function()
{
    try
    {
        // method GET
        const data1 = await kubeapi.get('namespaces/default/replicationcontrollers')
        // method POST
        const data2 = await kubeapi.post('namespaces/default/replicationcontrollers', require('./rc/nginx-rc.json'))
        // method PUT
        const data3 = await kubeapi.put('namespaces/default/replicationcontrollers/nginx', require('./rc/nginx-rc.json'))
        // method PATCH
        const data4 = await kubeapi.patch('namespaces/default/replicationcontrollers/nginx', [{ op: 'replace', path: '/spec/replicas', value: 2 }])
        // method DELETE
        const data5 = await kubeapi.delete('namespaces/default/replicationcontrollers/nginx')
    }
    catch(err){
        console.log(err)
    }
}()

method GET -> watch

using callback
var res = kubeapi.watch('watch/namespaces/default/pods', function(data){
	// message
}, function(err){
	// exit
}, [timeout])
using rxjs
kubeapi.watch('watch/namespaces/default/pods', [timeout]).subscribe(data=>{
    // message
}, err=>{
    // exit
})

kubectl (callback, promise, async/await)

example

    //kubectl['type']['action]([arguments], [flags], [callback]): Promise

    //callback
    kubect.pod.delete('pod_name', function(err, data){})
    kubect.pod.delete('pod_name', ['--grace-period=0'], function(err, data){})
    //promise
    kubect.pod.delete('pod_name').then()
    kubect.pod.delete('pod_name', ['--grace-period=0']).then()
    //async/await
    const data = await kubect.pod.delete('pod_name')
    const data = await kubect.pod.delete('pod_name',['--grace-period=0'])

excute command

    kubectl.command('get pod pod_name --output=json', function(err, data){})
    kubectl.command('get pod pod_name --output=json').then()
    const data = await kubectl.command('get pod pod_name --output=json')

Pods

get pod list

kubectl.pod.list(function(err, pods){})

//selector
var label = { name: nginx }
kubectl.pod.list(label, function(err, pods){})

get pod

kubectl.pod.get('nginx', function(err, pod){})

// label selector
kubectl.pod.list({ app: 'nginx' }, function(err, pods){}) 

create a pod

kubectl.pod.create('/:path/pods/nginx.yaml'), function(err, data){})

delete a pod

kubectl.pod.delete('nginx', function(err, data){})

log

kubectl.pod.log('pod_id1 pod_id2 pod_id3', function(err, log){})

ReplicationController

get rc list

kubectl.rc.list(function(err, pods){})

get a rc

kubectl.rc.get('nginx', function(err, pod){})

create a rc

kubectl.rc.create('/:path/pods/nginx.yaml'), function(err, data){})

delete a rc

kubectl.rc.delete('nginx', function(err, data){})

rolling-update by image name

kubectl.rc.rollingUpdate('nginx', 'nginx:vserion', function(err, data){})

rolling-update by file

kubectl.rc.rollingUpdateByFile('nginx', '/:path/rc/nginx-v2.yaml', function(err, data){})

change replicas

kubectl.rc.scale('nginx', 3, function(err, data){})

Service

get service list

kubectl.service.list(function(err, pods){})

get a service

kubectl.service.get('nginx', function(err, pod){})

create a service

kubectl.service.create('/:path/service/nginx.yaml'), function(err, data){})

delete a service

kubectl.service.delete('nginx', function(err, data){})

Node

get node list

kubectl.node.list(function(err, nodes){})

get a node

kubectl.node.get('node1', function(err, node){})

create a node

kubectl.node.create('/:path/nodes/node1.yaml'), function(err, node){})

delete a node

kubectl.node.delete('node1', function(err, node){})

Namespace

    kubectl.namespace['fn']

Daemonset

    kubectl.daemonset['fn']

Deployment

    kubectl.deployment['fn']

Secrets

    kubectl.secrets['fn']

endpoint

    kubectl.endpoint['fn']

ingress

    kubectl.ingress['fn']

node-k8s-client's People

Contributors

aabed avatar andreassolberg avatar chesleybrown avatar dkapanidis avatar gaballard avatar hatemismail avatar kaleocheng avatar kundralaci avatar ladlavj avatar llambeau avatar mmoonn2 avatar scampiuk avatar sciolizer avatar shenshouer avatar starefossen avatar timcrider avatar tslater avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-k8s-client's Issues

Create a new NPM build

There's code in your Reqest.ts file for pulling the config in via kubeconfig that doesn't exist in the index.js output from webpack. I've had to cd node_modules/k8s and run npm install and webpack.

Seems like you may just need to publish a new build to NPM.

Cant connect to k8

I am using AKS (Azure k8),trying to connect to cluster, here is my code `

var K8s = require('k8s');
var kubectl = K8s.kubectl({
endpoint: My API server address
, namespace: 'dev-op'
, binary: '/usr/local/bin/kubectl'
, auth: {
"token": "token taken from kubectl config view "
}
})

getting error Unable to connect to the server: x509: certificate signed by unknown authority
What is problem and what can I do?
Sorry if simple issue I cant find more information.

Context flag not in NPM published package

Firstly, thank you for making this package, it's really useful and exactly what I was looking for.

In one of your latest commits (23664c9) you added the context flag to the conifg for kubectl, which is great and exactly what I need. Unfortunately this hasn't been published to NPM, the module on NPM is back at commit 2609dd0

Can you guys republish the module with the latest code please? :) I'd greatly appreciate it.

Auth

Is there a specific way to authenticate with a token or using another method?

HTTP content-type headers for PATCH request

Few days ago I submitted PR #24. this PR is close because I saw that the fix was commit (cbd2163a74a34e734cc2c0c63e3ba22c1d5f2adbà) to set Content-Type HTTP header to application/strategic-merge-patch+json for PATCH request.
But another commit (41555e8) set Content-Type header to application/json-patch+json.

The PATCH request works for me only if header is Content-Type is application/strategic-merge-patch+json. When I use kubectl patch --v=8 [...] (to see what request are made to Kubernetes API) I see that Content-Type is application/strategic-merge-patch+json so it seems to be the right value.

kubectl.command from the readme does not work as expected

kubectl.command from the readme implies that K8s.kubectl(...).command should work. However, the method does not seem to be not define there. kube.node.command works although the command is type agnostic so maybe this should be exposed another way.

drain and uncordon

Can I use this to do 'kubectl drain' and 'kubectl uncordon' operations?

Pull requests?

Is there a way to submit a pull request for this library? I have a branch that fixes all the TypeScript errors encountered when trying to build with stricter TS options but I don't have permissions to push it up.

Edit: Ignore this issue!

tslint issues

I am trying to use this library to interact with kubernetes. I am having difficulties with typescript complier.

Error

$ tsc -p tsconfig.json
node_modules/k8s/index.ts(5,23): error TS7006: Parameter 'conf' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(8,13): error TS7005: Variable 'Buffer' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(12,5): error TS7008: Member 'strictSSL' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(13,5): error TS7008: Member 'domain' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(14,5): error TS7008: Member 'auth' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(42,25): error TS7006: Parameter 'kubeconfig' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(45,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(49,25): error TS7006: Parameter 'kubeconfig' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(49,37): error TS7006: Parameter 'context' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(52,41): error TS7006: Parameter 'x' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(56,22): error TS7006: Parameter 'kubeconfig' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(56,34): error TS7006: Parameter 'context' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(59,38): error TS7006: Parameter 'x' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(63,24): error TS7006: Parameter 'cluster' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(77,27): error TS7006: Parameter 'user' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(91,28): error TS7006: Parameter 'user' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(105,27): error TS7006: Parameter 'user' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(112,26): error TS7006: Parameter 'user' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(118,26): error TS7006: Parameter 'user' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(124,26): error TS7006: Parameter 'cluster' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(130,30): error TS7006: Parameter 'primise' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(130,39): error TS7006: Parameter 'callback' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(134,26): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(136,22): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(173,35): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(177,63): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(177,68): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(177,73): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(192,35): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(196,63): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(196,68): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(196,73): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(210,14): error TS7006: Parameter 'url' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(210,19): error TS7006: Parameter 'body' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(210,25): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(214,78): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(214,83): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(214,88): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(228,13): error TS7006: Parameter 'url' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(228,18): error TS7006: Parameter 'body' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(228,24): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(232,77): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(232,82): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(232,87): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(246,15): error TS7006: Parameter 'url' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(246,20): error TS7006: Parameter 'body' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(246,26): error TS7006: Parameter '_options' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(246,37): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(266,45): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(266,50): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(266,55): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(280,16): error TS7006: Parameter 'url' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(280,21): error TS7006: Parameter 'json' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(280,28): error TS7006: Parameter 'done' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(289,69): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(289,74): error TS7006: Parameter 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(289,79): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(303,15): error TS7006: Parameter 'url' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(303,20): error TS7006: Parameter 'message' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(303,30): error TS7006: Parameter 'exit' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(303,37): error TS7006: Parameter 'timeout' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(309,13): error TS7034: Variable 'res' implicitly has type 'any' in some locations where its type cannot be determined.
node_modules/k8s/lib/request.ts(311,46): error TS7006: Parameter 'observer' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(314,90): error TS7006: Parameter 'e' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(314,117): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(316,21): error TS7005: Variable 'res' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(337,37): error TS7006: Parameter 'err' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(346,30): error TS7006: Parameter 'data' implicitly has an 'any' type.
node_modules/k8s/lib/request.ts(348,16): error TS7006: Parameter 'err' implicitly has an 'any' type.

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "dist",
    "sourceMap": true,
    "noEmitOnError": true,
    "noImplicitAny": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
    // "./node_modules/**/*"  // Not working either
    // "**/node_modules/*"    // Not working 
  ]
}

Can someone help me on this.

Versionning discrepancies between npm and github

Currently, the npm version 0.4.14 is 2 patch version ahead of github 0.4.12. I'm guessing versions are manually set before pushing to npm; This should be fixed and eventually automated so that we get consistent versionning across both.

It's a problem for debugging since we cannot know for sure what version of the code hosted on Github is locally installed. And it's also an issue when looking at the sources to fill the documentation gaps.

Best way to exit a watch on success

When watching for a success case, such as a deployment finishing, what is the recommended way to signal the close of a watch? I tried a few possible options but nothing exited the watch as expected so far.

var res = kubeapi.watch('watch/namespaces/default/pods', function(data) {
    // some condition on data means we want to exit now
    // how do we signal here so we can call a callback with success?
    // e.g. callback(null, data);
}, function(err) {
    // error during deploy
    callback(err);
});

setTimeout(function() {
    // timeout if not successful after some time
    res.emit('close');
}, 30000);

Support kubeconfig file on API client

I'm working on a PR to add support for passing kubeconfig on the API client, similar to the binary client:

// Configure using kubeconfig
var kubeapi = K8s.api({
    kubeconfig: kubeconfigJSON
    ,version: '/api/v1'
})

so that an end-user can simply point to the existing kubeconfig and connect. Initially I wanted to follow same format as in binary client, but to avoid adding dependencies to read file and parse JSON, I'm thinking to use as input field an already parsed JSON format, though this diverges from the binary params.

[Question] Authenticating Kubernetes API(NodeJS) client using certificate not successful

I know this issue is not related to the repo. I am just posting it as the question. To start with, thanks for the amazing repo.

I have deployed a Kubernetes cluster in google cloud and trying to access it using the your kubernetes client.

To do so, we need to authenticate with cluster. I tried using just the Username and Password method. I get the following error:

{ [Error: unable to verify the first certificate] code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

Then I tried the authentication using the CAcert, ClientCert and ClientKey. I basically hardcoded the keys instead of importing it from the files. I am calling this API from a Lambda function, where I cant store the certs in files. Doing so, I get the below error:

[Error: error:0906D06C:PEM routines:PEM_read_bio:no start line]

I specified my keys like this:

var kubeapi = K8s.api({
  "endpoint": "https://35.187.203.114",
  "version": "/api/v1",
  "auth": {
    "caCert": "LST****KIU",
    "clientCert": "LST****KIU",
    "clientKey": "LST****KIU"
  }
});

My intuition is, authentication is possible only with keys. But I think I am doing something wrong with the certs. Do I need to create some other certificates out of this or is the method of using the certs is wrong ?

0.4.10 contains breaking changes

The Content-Type header for PATCH requests were changed, and this breaks existing behavior. I advise that you revoke the 0.4.10 version and release a new major version.

Support for Typescript (2?)

Recently we have moved to Typescript 2, and it seems stable and all our projects build, work, etc...

Problem

However building k8s with Typescript 2.0.0, I get the following errors:

app.ts(5,10): error TS2305: Module '"/home/laci/ktest/node_modules/k8s/index"' has no exported member 'K8s'.
node_modules/k8s/lib/request.ts(2,7): error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
node_modules/k8s/lib/request.ts(223,1): error TS4082: Default export of the module has or is using private name 'Request'.

From these errors, even earlier Typescript compilers were crying for no exported member 'K8s'.

Environment

I'm using [email protected] and npm 3+.
I prepared a very simple project with only a single app.ts, that would call K8s.api(...):

import { K8s } from 'k8s';

let kubeapi = K8s.api({
    endpoint: '...',
    version: '/api/v1',
    auth: {
        clientCert: '...',
        clientKey: '...',
        caCert: '...'
    },
    strictSSL: false
});

My tsconfig.json:

"compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "declaration": true
}

Proposals / Questions:

Looking at the 3 errors:

  • The first: can be my mistake(?), I'm unsure.
  • The second: Why do we need an external promise library?
  • The third: Maybe a little restructure, refactor could solve this. (?)

Only ship .js and .d.ts files when distributing to npm

Right now, users who are trying to consume this library with TypeScript using settings like noImplicitAny are having a negative user experience because the packaged .ts files are getting fully re-checked. See microsoft/TypeScript#15363 for an example of a problem caused by this.

Running TypeScript with --declaration to produce .d.ts files and adding your regular .ts files to an .npmignore file will prevent this issue.

Incorrect implementation for finding cluster from kubeconfig

You're currently using:

return kubeconfig.clusters.find(x => x.name === context.name)

Should be:

return kubeconfig.clusters.find(x => x.name === context.context.cluster)

To clarify, the current implementation assumes that the context name will always match the cluster name. The correct method is to read the context.cluster property of the context when searching for cluster.

Trouble connecting/accessing information from cluster

Hello,
I am trying to use this package to connect to Google Container Engine, which uses kubernetes.
The issue is I am unsure why I am getting either no value or undefined when I am trying to get a simple list of the pods.
here is my config:

var kubectl = k8s.kubectl({
  endpoint: 'https://[cluser ip]',
  namespace: 'default',
  binary: '/usr/local/bin/kubectl',
  auth: {
    username: '[user]',
    password: '[pass]'
  }
})

How I am calling the function:

  kubectl.pod.list(function (err, pods) {
    console.log(pods)
  })

any reason why I this is not working?

Does the post accept yaml manifest file ?

Thank you for your hard work. I have a question related to creating a pod using KubeAPI.

I am trying to create a pod using the following snippet:

var K8s = require('k8s');

var kubeapi = K8s.api({
  "endpoint": "https://***.**.**.**",
  "version": "/api/v1",
  "auth": {
    "clientCert": Buffer.from(clientCert, 'base64'),
    "clientKey": Buffer.from(clientKey, 'base64'),
    "caCert": Buffer.from(caCert, 'base64')
  }
});

  kubeapi.post("namespaces/default/pods", require("./podUbuntuManifest.yaml"), function(err, data){
    console.log("Create namespaces/default/pods");

    if (err) {
      console.log("error in namespaces/default/nodes");
      console.log(err);
    }

    console.log("printing success data of create namespaces/default/nodes");
    console.log(JSON.stringify(data));
  });

I get a ReferenceError in Yaml. But the yaml syntax is ok, I have verified with an online yamlLint. Only JSON is supported?

Can you provide an detailed example for creating a pod using the kubeApi?.

configure with kubernetes api

According to the description of the client, I created a test project in nodejs, I installed the k8s, and it was declared in an index, I created the instance variables and I created the get.nodes then me returns the error "the server doesn't have the resource type "nodes". You know why? Have some simple example of some activity that accomplishes this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.