Logging in IBM Control Desk Containers
Logging in the containerized environment is different from the normal application logging as the logs are created inside the container. Thus, it becomes difficult to access the application logs.
For ease of access, the container logs could be mounted outside the container on the worker nodes as shown in the below diagram:
Mount the logs directory from outside the container to a path in the host (worker node). Below is the configuration required in deployment file:
volumeMounts:
- mountPath: /logs
name: logs-backup
restartPolicy: Always
volumes:
- name: logs-backup
hostPath:
path: /root/logs
type: Directory
Handling Dynamic Logging during Scaling
- Add environment variable MY_POD_IP that automatically gets value of
POD IP of
deployment.
- env: - name: MY_POD_IP valueFrom: fieldRef: fieldPath: status.podIP
- Add configuration in the Websphere liberty server.xml and change the
logging file name to dynamically append MY_POD_IP which is IP of the
pod.
<logging messageFileName="messages-${env.MY_POD_IP}.log" />
These changes must be a part of the container image. Create a new docker image with these changes. After making above changes, the logs will be created separately for each pod in worker node and logging is dynamically handled during scale up.
kubectl get pods -o wide
The IP column of the command result shows the IP address of pod.
The messages file created will automatically get this IP address appended to the log file name and logs can be identified by the POD IP addresses.