-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of pod exec to examples/
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// 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.9' }); | ||
|
||
// Pod with single container | ||
let res = await client.api.v1.namespaces('namespace_name').pods('pod_name').exec.post({ | ||
qs: { | ||
command: [ 'ls', '-al' ] | ||
} | ||
}); | ||
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' | ||
} | ||
}); | ||
console.log(res.body); | ||
|
||
} catch (err) { | ||
console.error('Error: ', err); | ||
} | ||
} | ||
|
||
main(); |