Skip to content

Commit

Permalink
Add example of pod exec to examples/
Browse files Browse the repository at this point in the history
  • Loading branch information
gempesaw committed Sep 16, 2018
1 parent 8901d75 commit 03058ae
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/pod-exec.js
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();

0 comments on commit 03058ae

Please sign in to comment.