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 = // use kubectl var kubectl = K8s //use restful apivar kubeapi = K8s // Configure using kubeconfigvar kubeapi = K8s var kube = K8s;
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 GETkubeapi // method POSTkubeapi// method PUTkubeapi// method PATCHkubeapi// method DELETEkubeapi
using promise
// method GETkubeapi// method POSTkubeapi// method PUTkubeapi// method PATCHkubeapi// method DELETEkubeapi
using async/await
!{ try // method GET const data1 = await kubeapi // method POST const data2 = await kubeapi // method PUT const data3 = await kubeapi // method PATCH const data4 = await kubeapi // method DELETE const data5 = await kubeapi catcherr console }
method GET -> watch
using callback
var res = kubeapi
using rxjs
kubeapi
kubectl (callback, promise, async/await)
example
//kubectl['type']['action]([arguments], [flags], [callback]): Promise //callback kubectpod kubectpod //promise kubectpod kubectpod //async/await const data = await kubectpod const data = await kubectpod
excute command
kubectl kubectl const data = await kubectl
Pods
get pod list
kubectlpod //selectorvar label = name: nginx kubectlpod
get pod
kubectlpod // label selectorkubectlpod
create a pod
kubectlpod {})
delete a pod
kubectlpod
log
kubectlpod
ReplicationController
get rc list
kubectlrc
get a rc
kubectlrc
create a rc
kubectlrc {})
delete a rc
kubectlrc
rolling-update by image name
kubectlrc
rolling-update by file
kubectlrc
change replicas
kubectlrc
Service
get service list
kubectlservice
get a service
kubectlservice
create a service
kubectlservice {})
delete a service
kubectlservice
Node
get node list
kubectlnode
get a node
kubectlnode
create a node
kubectlnode {})
delete a node
kubectlnode
Namespace
kubectlnamespace'fn'
Daemonset
kubectldaemonset'fn'
Deployment
kubectldeployment'fn'
Secrets
kubectlsecrets'fn'
endpoint
kubectlendpoint'fn'
ingress
kubectlingress'fn'