Get Application Logs from the Kubernetes Cluster

You can get logs for your application from pods within the Kubernetes cluster.

  1. Open a command-line window.
  2. Locate the pods for your application. Replace the <app-name> placeholder.
    kubectl get pods | grep "<app-name>"

    Example:

    $ kubectl get pods | grep "webapp01"
    webapp01-deployment-84b7b6b5d4-5lnhb   1/1     Running   0        10d
    webapp01-deployment-84b7b6b5d4-qxfbs   1/1     Running   0        10d
  3. Fetch logs for your application from a pod. Replace the <pod-name> placeholder with the pod name of the previous step.
    kubectl logs --tail=100 <pod-name>

    Example:

    $ kubectl logs --tail=100 webapp01-deployment-84b7b6b5d4-5lnhb
    Not a secure app, removing idcs.jsp
    Jan 21, 2019 9:16:53 AM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler ["http-bio-8080"]
    Jan 21, 2019 9:16:53 AM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Tomcat
    Jan 21, 2019 9:16:53 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.50
    Jan 21, 2019 9:16:53 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
    INFO: No global web.xml found
    Jan 21, 2019 9:16:53 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-8080"]
    Jan 21, 2019 6:56:47 PM org.apache.coyote.http11.AbstractHttp11Processor process
    INFO: Error parsing HTTP request header
     Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.