Skip to content

Commit 6bd7e94

Browse files
authored
Merge pull request #690 from hardillb/master
Follow Log Example.
2 parents 6c8bd04 + 25653ca commit 6bd7e94

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

examples/follow-logs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const stream = require('stream');
2+
const k8s = require('@kubernetes/client-node');
3+
4+
const kc = new k8s.KubeConfig();
5+
kc.loadFromDefault();
6+
7+
const log = new k8s.Log(kc);
8+
9+
const logStream = new stream.PassThrough();
10+
11+
logStream.on('data', (chunk) => {
12+
// use write rather than console.log to prevent double line feed
13+
process.stdout.write(chunk);
14+
});
15+
16+
log.log('default', 'pod1', 'container1', logStream, (err) => {console.log(err)}, {follow: true, tailLines: 50, pretty: false, timestamps: false})
17+
.then(req => {
18+
// disconnects after 5 seconds
19+
setTimeout(function(){
20+
req.abort();
21+
}, 5000);
22+
});
23+

0 commit comments

Comments
 (0)