How to logrotate kubernetes' log on windows node?

4/16/2019

According to k8s on Microsoft,i have deployed a windows k8s cluster(version 1.12.6) which has one master node on Linux Server and two worker nodes on Windows19 Server. However, the log file produced and locked by kubeletkube-proxy process occupied several GB disk space。what can I do to rotate the log file for just saving recent days' data on windows Server?

I know Stop and Start the kubeletkube-proxy process will help, but my boss said no! :(

I have tried some ways:

  1. window logrotate tool
# logrotate config
"c:\k\log\kube-proxy.exe.iZcrhcz0q5s4ykZ.NT AUTHORITY_SYSTEM.log.INFO.20190416-162533.2272" {
    daily
    rotate 5
    size 100M
    copytruncate
    missingok
    ifempty
}
  1. powershell cmd
rm xxx.log
mv xxx.log
Clear-Content -Path $logFile -Force

All failed!

Error Message: The process cannot access the file 'C:\k\log\xxx.log' because it is being used by another process.

I have some questions:

  • 1: Does k8s' log system support logrotate on Windows?
  • 2: Does Windows Server provide a mechanism to rotate log?

Thanks for any reply!

-- Jimmy Zhang
kubernetes
logrotate
windows

1 Answer

4/17/2019

kubelet/kube-proxy use klog, klog rotate when file size > 1.8G

func (sb *syncBuffer) Write(p []byte) (n int, err error) {
    if sb.nbytes+uint64(len(p)) >= MaxSize {
        if err := sb.rotateFile(time.Now(), false); err != nil {
            sb.logger.exit(err)
        }
    }
    n, err = sb.Writer.Write(p)
    sb.nbytes += uint64(n)
    if err != nil {
        sb.logger.exit(err)
    }
    return
}

you can just delete older files.

-- jxiewei
Source: StackOverflow