[英]Jenkins on Kubernetes - Get logs of containers from kubectl
I'm working with Jenkins on Kubernetes and I'm not able to retrieve the logs of containers used on the pipelines.我正在与 Kubernetes 上的 Jenkins 合作,但我无法检索管道上使用的容器的日志。
For example using the following pipeline:例如使用以下管道:
pipeline { agent { kubernetes { containerTemplate { name 'alpine' image 'alpine' command 'tail -f /dev/null'} } } stages { stage('sample'){ steps{ container('alpine'){ echo "Hello world" sleep 600 } } } } }
everything works fine and I can see "Hello world" printed on Jenkins console, but I'd also like to get it as output from the command kubectl get logs pod-name -c alpine
.一切正常,我可以在 Jenkins 控制台上看到“Hello world”,但我也想通过命令
kubectl get logs pod-name -c alpine
将其作为 output 获取。 I suppose that kubectl logs
display what is written on stdout
/ stderr
by the command used as entrypoint in the container ( tail -f /dev/null
in this case ) and that that's the reason a I don't get "Hello world", but I don't get how to achieve what I want.我想
kubectl logs
显示在容器中用作入口点的命令(在本例中为tail -f /dev/null
)在stdout
/ stderr
上写入的内容,这就是我没有得到“Hello world”的原因,但我不知道如何实现我想要的。
I also saw a workaround suggested on Docker documentation:我还看到了 Docker 文档中建议的解决方法:
The official nginx image creates a symbolic link from /var/log/nginx/access.log to /dev/stdout, and creates another symbolic link from /var/log/nginx/error.log to /dev/stderr, overwriting the log files and causing logs to be sent to the relevant special device instead.
官方的 nginx 镜像创建了一个从 /var/log/nginx/access.log 到 /dev/stdout 的符号链接,并创建了另一个从 /var/log/nginx/error.log 到 /dev/stderr 的符号链接,覆盖了日志文件并导致日志被发送到相关的特殊设备。 See the Dockerfile.
请参阅 Dockerfile。
but I don't think that solution fits my problem.但我认为该解决方案不适合我的问题。
This worked for me这对我有用
containerTemplate { name 'alpine', image 'alpine', ttyEnabled: true, command 'cat' }
Reference: https://github.com/jenkinsci/kubernetes-plugin#container-group-support参考: https://github.com/jenkinsci/kubernetes-plugin#container-group-support
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.