-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s.js
executable file
·62 lines (38 loc) · 1.22 KB
/
k8s.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* https://github.com/godaddy/kubernetes-client
*
* 411321681@qq.com
* 老冯
*
*/
const Client=require('kubernetes-client').Client
const { KubeConfig } = require('kubernetes-client')
const kubeconfig = new KubeConfig()
kubeconfig.loadFromFile('/Users/fengxiang/.kube/config')
const Request = require('kubernetes-client/backends/request')
const backend = new Request({ kubeconfig })
//const client = new Client({ version: '1.13' })
const client = new Client({ backend, version: '1.13' })
async function test1() {
const namespaces = await client.api.v1.namespaces.get();
console.log(JSON.stringify(namespaces))
}
//从服务获取数据
async function get(){
const deployment = await client.apis.apps.v1.namespaces('default').deployments.get()
console.log(JSON.stringify(deployment,null,"\t"))
}
//从服务获取数据
async function getpods(){
let res = await client.api.v1.namespaces('namespace_name').pods();
console.log(JSON.stringify(res,null,"\t"))
}
//从服务获取数据
async function getservice(){
let res = await client.api.v1.namespaces('namespace_name').service();
console.log(JSON.stringify(res,null,"\t"))
}
//test1();
//get();
//getpods();
getservice();