Simplified Kubernetes API client for FIBJS, supported:
- Kubernetes API v1.13
- Kubernetes API v1.12
- Kubernetes API v1.11
- Kubernetes API v1.10
- Kubernetes API v1.9
- Kubernetes API v1.8
- Kubernetes API v1.7
Via fibjs:
fibjs --install fib-k8s-client
Or, via npm:
npm install fib-k8s-client
/*
* host: Kubernetes domain & port
* version: API version
* auth.token: Kubernetes access token
*/
const conf = {
"host": "https://DOMAIN:PORT",
"version": "1.13",
"auth": {
"token": "k8s access token"
}
}
const { Client } = require('fib-k8s-client');
client = new Client(conf);
Access namespace list:
const namespaces = client.api.v1.namespaces.get();
Create namespace:
const ns_json = require('./namespace.json');
client.namespaces.create(ns_json);
Access specific namespace:
client.api.v1.namespaces('namespace_name').get();
Remove namespace:
client.api.v1.namespaces('namespace_name').delete();
Create pod:
const pod_json = require('./pod.json');
client.api.v1.namespaces('namespace_name').pods.post({ body: pod_json })
Access pod from specific namespace:
client.api.v1.namespaces('namespace_name').pods('pod_name').get()
remove pod:
client.api.v1.namespaces('namespace_name').pods('pod_name').delete();
fib-k8s-client supports .delete
, .get
, .patch
, .post
, and .put
.
You could find more detailed usage in test cases from test directory.
Full API interfaces documentation could find from docs directory(need download first):
You could use provided API specification json to init your API client:
const { Client } = require('fib-k8s-client');
const conf = {
"host": "https://DOMAIN:PORT",
"auth": {
"token": "k8s access token"
}
}
const spec = require("./api_spec.json")
client = new Client(conf, spec);
fibjs test