AKS icon indicating copy to clipboard operation
AKS copied to clipboard

syslog/messages/kern.log rollover not working on aks nodes

Open saaror opened this issue 5 years ago • 9 comments

What happened: syslog/messages/kern.log rollover not working on aks linux nodes. Details of the issue here. https://docs.microsoft.com/en-us/answers/questions/244101/syslogmessageskernlog-rollover-not-working-on-aks.html

What you expected to happen: Roll-over should work

Resolution The issue is related to the OMS agent bug, which is hot-fixed for next week OMS agent update where we are removing log rotation settings in containers. In the meanwhile here is the short term solution you can use. The customer can download the logrotate-mitigation.sh file I have attached to the incident. In the same directory as the downloaded logrotate-mitigation.sh and with the kubectl context pointing to the correct cluster, run the following (I have also attached this as a file called all-omsagent-logrotate-mitigation.sh):

for pod in $(kubectl -n kube-system get pods --output=jsonpath={.items..metadata.name}); do
    if [[ $pod == omsagent-* ]] && [[ $pod != omsagent-win-* ]]; then

      kubectl cp -n kube-system logrotate-mitigation.sh $pod:/opt/logrotate-mitigation.sh
      kubectl exec -it $pod -n kube-system -- bash -c "chmod +x /opt/logrotate-mitigation.sh"
      kubectl exec -it $pod -n kube-system -- bash -c "/opt/logrotate-mitigation.sh"
    fi
done

This runs the script on every omsagent container. The next time the node tries to rotate the files, there won't be a conflict with the container settings and it will start working again. The script works as follows:

# Remove logrotate settings for the container that overlap with node logrotate settings
# These are included in etc/logrotate.conf that the etc/cron.daily uses for the logrotate command
rm /etc/logrotate.d/alternatives /etc/logrotate.d/apt /etc/logrotate.d/rsyslog

# Move *.1 file so that logrotation can start again correctly the next time the node rotates the files

if [ -s /var/log/syslog.1 ] && [ ! -s /var/log/syslog ]; then
    mv /var/log/syslog.1 /var/log/syslog
fi
if [ -s /var/log/kern.log.1 ] && [ ! -s /var/log/kern.log ]; then
    mv /var/log/kern.log.1 /var/log/kern.log
fi
if [ -s /var/log/messages.1 ] && [ ! -s /var/log/messages ]; then
    mv /var/log/messages.1 /var/log/messages
fi

However, until the release with the actual fix goes out, the script would need to be run again for that pod if the container restarts.

Also note that this will only fix the file rotation and the large file for syslog won't be removed for 7 days (and kern.log and messages for 4 days) based on the rotation settings (rotates daily and keeps 7 or 4 files). If the customer would like to delete the large file, they should only do so after it has been rotated correctly (after the script is run and after the node rotates the files, which it does once a day).

saaror avatar Apr 02 '21 18:04 saaror

@vishiy, @saaror would you be able to assist?

Issue Details

What happened: syslog/messages/kern.log rollover not working on aks linux nodes. Details of the issue here. https://docs.microsoft.com/en-us/answers/questions/244101/syslogmessageskernlog-rollover-not-working-on-aks.html

What you expected to happen: Roll-over should work

Resolution The issue is related to the OMS agent bug, which is hot-fixed for next week OMS agent update where we are removing log rotation settings in containers. In the meanwhile here is the short term solution you can use. The customer can download the logrotate-mitigation.sh file I have attached to the incident. In the same directory as the downloaded logrotate-mitigation.sh and with the kubectl context pointing to the correct cluster, run the following (I have also attached this as a file called all-omsagent-logrotate-mitigation.sh):

for pod in $(kubectl -n kube-system get pods --output=jsonpath={.items..metadata.name}); do if [[ $pod == omsagent-* ]] && [[ $pod != omsagent-win-* ]]; then

  kubectl cp -n kube-system logrotate-mitigation.sh $pod:/opt/logrotate-mitigation.sh
  kubectl exec -it $pod -n kube-system -- bash -c "chmod +x /opt/logrotate-mitigation.sh"
  kubectl exec -it $pod -n kube-system -- bash -c "/opt/logrotate-mitigation.sh"
fi

done

This runs the script on every omsagent container. The next time the node tries to rotate the files, there won't be a conflict with the container settings and it will start working again. The script works as follows:

Remove logrotate settings for the container that overlap with node logrotate settings

These are included in etc/logrotate.conf that the etc/cron.daily uses for the logrotate command

rm /etc/logrotate.d/alternatives /etc/logrotate.d/apt /etc/logrotate.d/rsyslog

Move *.1 file so that logrotation can start again correctly the next time the node rotates the files

if [ -s /var/log/syslog.1 ] && [ ! -s /var/log/syslog ]; then mv /var/log/syslog.1 /var/log/syslog fi if [ -s /var/log/kern.log.1 ] && [ ! -s /var/log/kern.log ]; then mv /var/log/kern.log.1 /var/log/kern.log fi if [ -s /var/log/messages.1 ] && [ ! -s /var/log/messages ]; then mv /var/log/messages.1 /var/log/messages fi

However, until the release with the actual fix goes out, the script would need to be run again for that pod if the container restarts.

Also note that this will only fix the file rotation and the large file for syslog won't be removed for 7 days (and kern.log and messages for 4 days) based on the rotation settings (rotates daily and keeps 7 or 4 files). If the customer would like to delete the large file, they should only do so after it has been rotated correctly (after the script is run and after the node rotates the files, which it does once a day).

Anything else we need to know?:

Author: saaror
Assignees: saaror
Labels:

addon/container-insights, known-issue

Milestone: -

ghost avatar Apr 02 '21 18:04 ghost

Hey, just wondering if there is an update on this. I am seeing pod evictions from disk pressure due to very large log files in "/var/log", (>50GB). Has the fix already been deployed and if so will we need to restart nodes or take other action before we see the effects?

acksmaggart avatar Apr 20 '21 17:04 acksmaggart

Also, just to confirm @saaror, does that second code snippet show the contents of logrotate-mitigation.sh? Or is that script available somewhere else?

acksmaggart avatar Apr 20 '21 18:04 acksmaggart

@MaxTaggart Yes, the second code snippet is the content of lograte-mitigation.sh.

The fix will roll-out as part of next week train.

No restart is needed either, but you will need to still run the if statements part of the script if the node is already in the bad state.

saaror avatar Apr 20 '21 19:04 saaror

Hi, yesterday had to clean about 90GB of log off our AKS node, because pods where evicted due to disk pressure. I'd like to prevent similar situations in the future. However for me it the state of this issue is not clear.

The fix will roll-out as part of next week train.

@saaror Was this fix already released? If so where can I find further information like patch notes for the release?

No restart is needed either, but you will need to still run the if statements part of the script if the node is already in the bad state.

Does "running the if statement part" mean to move the *.1 files? E.g. moving /var/log/syslog.1 to /var/log/syslog.

Panzki avatar May 18 '21 07:05 Panzki

Hello, I am being affected by this issue and would appreciate an update

danielsimpson avatar Jun 10 '21 00:06 danielsimpson

Hi @danielsimpson, we opened a support request in our Azure account and the support agent told us, that the fix should be released on 2020-07-02 for the West Europe region.

Panzki avatar Jun 14 '21 11:06 Panzki

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

ghost avatar Aug 13 '21 14:08 ghost

This is already resolved. Closing the issue. Feel free to open if you still see the issue.

saaror avatar Aug 13 '21 16:08 saaror