From 03058ae1de71d11e2d531e32e6275e602941f790 Mon Sep 17 00:00:00 2001 From: Daniel Gempesaw Date: Sun, 16 Sep 2018 17:46:06 -0400 Subject: [PATCH] Add example of pod exec to examples/ --- examples/pod-exec.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/pod-exec.js diff --git a/examples/pod-exec.js b/examples/pod-exec.js new file mode 100644 index 00000000..d00866b4 --- /dev/null +++ b/examples/pod-exec.js @@ -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();