-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathpod-exec.js
37 lines (33 loc) · 940 Bytes
/
pod-exec.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
//
// Execute commands non-interactively in a pod
//
const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config
async function main () {
try {
const client = new Client({ config: config.fromKubeconfig(), version: '1.13' })
// Pod with single container
let res = await client.api.v1.namespaces('namespace_name').pods('pod_name').exec.post({
qs: {
command: ['ls', '-al'],
stdout: true,
stderr: true
}
})
console.log(res.body)
console.log(res.messages)
// Pod with multiple containers /must/ specify a container
res = await client.api.v1.namespaces('namespace_name').pods('pod_name').exec.post({
qs: {
command: ['ls', '-al'],
container: 'container_name',
stdout: true,
stderr: true
}
})
console.log(res.body)
} catch (err) {
console.error('Error: ', err)
}
}
main()