简体   繁体   中英

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). In one of the steps I am running java application in one of the containers. Application is writing logs to stdout. I would like to see the logs from this application in Stackdriver. How can I achieve it? Currently I am not able to see these logs in Stackdriver nor in Jenkins logs.

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. 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).

If you are already running the Jenkin on GCP instance it would be quite easy and directly get the logs to Stackdriver.

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

You can also integrate the Agent with java

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

You should also checkout using the Bluemedora

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM