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

The limitation of above approach is that logging fails when application scales. Also the logging approach fails when there are two or more pods created on one worker node, as the messages.log file is overwritten. To handle this case, add configuration to the deployment yaml and the websphere configuration:
  1. 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      
    
  2. 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.

Logging file with name messages-<POD IP>.log is created after successful deployment of above changes. Each Pod has an IP address in Kubernetes. The pod IP Address can be viewed by executing below command:
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.