首页 文章

记录消耗Google Cloud Kubernetes窗格中磁盘空间的日志

提问于
浏览
3

我们在Google Cloud Platform Kubernetes群集中有一个pod,将JsonFormatted写入StdOut . 这是由Stackdriver开箱即用的 . 但是,我们看到pod的磁盘使用量正在增长和增长,我们无法理解如何在部署日志轮换上设置最大大小 .

有关Google Cloud和Kubernetes的文档尚不清楚 .

这只是最后一小时:

Memory consumption on a Pod

1 回答

  • 0

    您确定由于日志而导致磁盘的磁盘使用率很高吗?如果应用程序将日志写入stdout,则它不会使用pod中的任何磁盘空间 . 所有日志通常都存储在节点文件系统的日志文件中,并且可以由节点logrotate进程管理 .

    也许应用程序使用pod的磁盘空间来处理其他内容,比如临时文件或调试信息?

    以下是documentation与日志轮换相关的部分:

    在节点级别进行日志记录:容器化应用程序写入stdout和stderr的所有内容都由容器引擎处理并重定向到某处 . 例如,Docker容器引擎将这两个流重定向到日志驱动程序,该驱动程序在Kubernetes中配置为以json格式写入文件 . 节点级日志记录中的一个重要考虑因素是实现日志轮换,以便日志不会占用节点上的所有可用存储 . Kubernetes目前不负责轮换日志,而是部署工具应该设置解决方案来解决这个问题 . 例如,在由kube-up.sh脚本部署的Kubernetes集群中,有一个logrotate工具配置为每小时运行一次 . 您还可以设置容器运行时自动轮换应用程序的日志,例如通过使用Docker的log-opt . 在kube-up.sh脚本中,后一种方法用于GCP上的COS映像,前一种方法用于任何其他环境 . 在这两种情况下,默认情况下,旋转配置为在日志文件超过10MB时发生 . 例如,您可以在相应的脚本中找到有关kube-up.sh如何在GCP上设置COS映像日志记录的详细信息 .

    以下是与logrotate相关的脚本的一部分:

    # Installs logrotate configuration files
    function setup-logrotate() {
      mkdir -p /etc/logrotate.d/
      # Configure log rotation for all logs in /var/log, which is where k8s services
      # are configured to write their log files. Whenever logrotate is ran, this
      # config will:
      # * rotate the log file if its size is > 100Mb OR if one day has elapsed
      # * save rotated logs into a gzipped timestamped backup
      # * log file timestamp (controlled by 'dateformat') includes seconds too. This
      #   ensures that logrotate can generate unique logfiles during each rotation
      #   (otherwise it skips rotation if 'maxsize' is reached multiple times in a
      #   day).
      # * keep only 5 old (rotated) logs, and will discard older logs.
      cat > /etc/logrotate.d/allvarlogs <<EOF
    /var/log/*.log {
        rotate ${LOGROTATE_FILES_MAX_COUNT:-5}
        copytruncate
        missingok
        notifempty
        compress
        maxsize ${LOGROTATE_MAX_SIZE:-100M}
        daily
        dateext
        dateformat -%Y%m%d-%s
        create 0644 root root
    }
    EOF
    
    }
    

相关问题