Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
javascript/examples/follow-logs.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (23 sloc)
654 Bytes
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
const stream = require('stream'); | |
const k8s = require('@kubernetes/client-node'); | |
const kc = new k8s.KubeConfig(); | |
kc.loadFromDefault(); | |
const log = new k8s.Log(kc); | |
const logStream = new stream.PassThrough(); | |
logStream.on('data', (chunk) => { | |
// use write rather than console.log to prevent double line feed | |
process.stdout.write(chunk); | |
}); | |
log.log('default', 'pod1', 'container', logStream, {follow: true, tailLines: 50, pretty: false, timestamps: false}) | |
.catch(err => { | |
console.log(err); | |
process.exit(1); | |
}) | |
.then(req => { | |
// disconnects after 5 seconds | |
if (req) { | |
setTimeout(function(){ | |
req.abort(); | |
}, 5000); | |
} | |
}); |