Log not found by running as a deployment but in a pod

Hi, I’ve encountered an issue with a Spring Boot application where the log files, generated upon startup, stored under the logs folder of it starts, are visible when using kubectl run , but not when deploying through a YAML file. Below are the Dockerfile and deployment.yaml for reference:

Dockerfile

FROM openjdk:11

WORKDIR /home/web

# RUN echo "Asia/Shanghai" > /etc/timezone

ENV TZ=Asia/Shanghai

COPY addon.jar /home/web

CMD ["java","-jar","/home/web/addon.jar"]

Oddly, when running k run test --image docker.io/lkfan1/addon-demo:v10 , I can observe the logs folder using the exec command. However, the logs folder is not visible when deploying using the following deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jira-addon
  labels:
    app: jira-addon
    tier: backend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: jira-addon
      tier: backend
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: jira-addon
        tier: backend
    spec:
      containers:
        - name: jira-addons
          image: docker.io/lkfan1/addon-demo:v10
          imagePullPolicy: Always 
          ports:
            - name: https
              containerPort: 8443
            - name: http
              containerPort: 8080
          securityContext:
            runAsNonRoot: true
            runAsUser: 1001
          volumeMounts:
            - mountPath: /home/
              name: addon-data
      volumes:
        - name: addon-data
          persistentVolumeClaim:
            claimName: addon-data-pvc

Anyone can help on this?

Have you made any progress with your issue? I’m in the same boat.

Hi @agalisteo

I’m not entirely certain of the exact steps I took to resolve this issue, as it’s been quite some time since it was initially posted. I can only recall that the issue stemmed from either misconfigured log files or a problem in the Dockerfile used to generate the application image.

I will share what I got to resolve this or that problem and hope it can help.

application-dev.yaml

logging:
  file:
    path: jiraAddon/logs/${MY_POD_NAME:default}

demployment.yaml

******
******
          env:
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          volumeMounts:
            - name: logs
              mountPath: /home/web/jiraAddon/logs
******
******

      volumes:
        - name: logs
          persistentVolumeClaim:
            claimName: addon-log-pvc

Dockerfile

FROM openjdk:11

WORKDIR /home/web

ARG PROFILE
ENV PROFILE_ENV ${PROFILE}

# RUN echo "Asia/Shanghai" > /etc/timezone

ENV TZ=Asia/Shanghai

COPY atlassian-connect-spring-boot-sample-thymeleaf-2.0-SNAPSHOT.jar /home/web

CMD java -jar /home/web/atlassian-connect-spring-boot-sample-thymeleaf-2.0-SNAPSHOT.jar --spring.profiles.active=$PROFILE_ENV