I'm aware of the usual way to "tail --follow" logs of a Kubernetes service:
kubectl logs -f -lapp=service-name --all-containers=trueBut every time I push a change to this service the kubectl dies when the pods get killed and I have to run it again.
Example error message:
Received interrupt, cleaning up... rpc error: code = Unknown desc = Error: No such container: b48a1ad3c0080680465c79903d03748a026becf397bc780921674b2f0d7078ffReceived interrupt, cleaning up...
rpc error: code = Unknown desc = Error: No such container: 6258e31702ea678eacec5ad0df15b5620b5609cd5e4822f2e4991fd26c9906b6 $
What I wonder is if there is a way to tell Kubernetes to keep looking for new pods which match the -lapp=service-name tag and tail them. A bit similar to tail --follow=name --retry
I suppose I can run the command in a simple shell loop but was wondering if there is something smarter that can use Kubernetes, one which will avoid lots of errors while the new pods get deployed.
What about instead of using stern?
Basically, you can use the same structure of the command, just replace kubectl logs -f -lapp=service-name --all-containers=true into stern -l app=service-name