[Solved] Logs sent to console using logback configuration in java app, not visible in Kubernetes using kubectl logs

According to the Kubenetes documentation, all output (that a containerized application writes to stdout and stderr) is redirected to a JSON file by default. You can access it by using kubectl logs.

Let’s test this feature by creating a simple pod that outputs numbers in stdout:

kubectl create -f https://k8s.io/docs/tasks/debug-application-cluster/counter-pod.yaml

counter-pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: counter
spec:
  containers:
  - name: count
    image: busybox
    args: [/bin/sh, -c,
            'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done']

where:
counter – name of the pod
count – name of the container inside “counter” pod

You can access the content of that file by running:

$ kubectl logs counter

You can access a log file of previously crashed container in a pod by the following command:

$ kubectl logs --previous

In case of multiple containers in the pod, you should add the name of the container as follows:

$ kubectl logs counter -c count

When the pod is removed from the cluster, all its logs (current and previous) are also removed.

Ensure you configure stdout in application correctly, and the output to stdout in your application is not silently skipped by any reason.

ok so this finally got resolved. The issue was with the logs not being flushed.

In the PatternLayout the %n was missing. Hence everything was going into some buffer I guess and not reaching the console.

Read more here: Source link