简体   繁体   English

如何查看日志是来自在 Jenkins Kubernetes 容器上运行的 Java 应用程序的 Stackdriver

[英]How to see logs is Stackdriver from Java application run on Jenkins Kubernetes container

I've created a Jenkins pipeline and I am running it on GKE (using Kubernetes plugin).我创建了一个 Jenkins 管道,并在 GKE 上运行它(使用 Kubernetes 插件)。 In one of the steps I am running java application in one of the containers.在其中一个步骤中,我在其中一个容器中运行 java 应用程序。 Application is writing logs to stdout.应用程序正在将日志写入标准输出。 I would like to see the logs from this application in Stackdriver.我想在 Stackdriver 中查看此应用程序的日志。 How can I achieve it?我怎样才能实现它? Currently I am not able to see these logs in Stackdriver nor in Jenkins logs.目前我无法在 Stackdriver 和 Jenkins 日志中看到这些日志。

My pipeline:我的管道:

podTemplate(cloud: 'kubernetes',
        yaml: """
apiVersion: v1
kind: Pod
spec:
  securityContext:
    runAsUser: 0
  containers:
  - name: maven
    image: maven:3.6.3-jdk-11
    resources:
      requests:
        cpu: "1"
        memory: "1Gi"
        ephemeral-storage: "20Mi"
      limits:
        cpu: "2"
        memory: "4Gi"
        ephemeral-storage: "1Gi"
    command:
    - cat
    tty: true
"""
) {
    node(POD_LABEL) {
        stage('Run app') {
            container('maven') {
                sh "java -jar my-app.jar &"
            }
        }
    }
}

=== EDIT === === 编辑 ===

My master Jenkins is installed on one of the GKE pods and each PR validation triggers another pod having the mentioned container with java application.我的主 Jenkins 安装在其中一个 GKE Pod 上,每个 PR 验证都会触发另一个具有上述容器和 Java 应用程序的 Pod。 It looks that the jenkins slave agent is gathering the logs (but not attaching them to build log as the java app is run in background).看起来 jenkins 从代理正在收集日志(但没有将它们附加到构建日志,因为 java 应用程序在后台运行)。

If you are already running the Jenkin on GCP instance it would be quite easy and directly get the logs to Stackdriver.如果您已经在 GCP 实例上运行 Jenkin,那么将非常简单,直接将日志获取到 Stackdriver。

https://faun.pub/jenkins-on-google-compute-engine-611bd86e295b https://faun.pub/jenkins-on-google-compute-engine-611bd86e295b

You can also integrate the Agent with java您还可以将 Agent 与 java 集成

Reference : https://medium.com/google-cloud/java-logging-on-cloud-run-with-stackdriver-9786d6fdbe17参考: https : //medium.com/google-cloud/java-logging-on-cloud-run-with-stackdriver-9786d6fdbe17

You should also checkout using the Bluemedora您还应该使用Bluemedora结帐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在kubernetes内运行的jenkins管道中运行sidecar容器 - How to run sidecar container in jenkins pipeline running inside kubernetes Kubernetes 上的 Jenkins - 从 kubectl 获取容器日志 - Jenkins on Kubernetes - Get logs of containers from kubectl 如何在 Kubernetes 上运行 Jenkins 和 Docker? - How to run Jenkins with Docker on Kubernetes? 从jenkins内的docker容器获取日志 - Getting logs from a docker container inside jenkins 如何在 Kubernetes 中检查失败的容器日志 - How to check failed container logs in Kubernetes 配置 fluentd 以在 Kubernetes 集群中选择 Jenkins 作业/应用程序日志 - Configure fluentd to pick Jenkins job/application logs in a kubernetes cluster 通过Jenkins作业从在kubernetes pod中运行的docker容器中运行bash脚本 - Run a bash script from a docker container running in kubernetes pod via Jenkins job 如何使用Groovy和Kubernetes插件从Jenkins Pipeline运行Kafka? - How to run Kafka from Jenkins Pipeline using Groovy and Kubernetes plugin? 如何从 jenkins docker 容器在主机上运行 shell 脚本? - How to run shell script on Host from jenkins docker container? 如何从 jenkins 脚本在 docker 容器内运行命令 - How to run a command inside a docker container from a jenkins script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM