Kubernetes日志路径

Kubernetes日志路径配置

Kubernetes各组件默认不将日志输出到文件,可能是不好控制吧,默认只输出到控制台

kubelet

  1. 具体配置如下,kuberlet.service.d/10-kubeadm.conf

    一共四个环境变量,真是吃饱撑得没事做,可能是为了功能更明确一点吧

    具体日志修改的变量在/etc/sysconfig/kubelet文件中,如下 (--v=5 是日志级别的定义等级包含了debug模式,有助于在排错的,正常运行可以关闭)

    二个参数:--logtostderr默认是true代表输出到控制台上,--log-dir默认是空,代表输出到控制台上,亲测如果需要输出到文件中,目录必须是/var/log/kubernetes,如果有朋友测试其它的目录可以,告诉一下

    <root@HK-K8S-WN4 /usr/lib/systemd/system/kubelet.service.d># cat 10-kubeadm.conf 
    # Note: This dropin only works with kubeadm and kubelet v1.11+
    [Service]
    Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
    Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
    # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
    EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
    # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
    # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
    EnvironmentFile=-/etc/sysconfig/kubelet
    ExecStart=
    ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
  2. 重启服务

    systemctl daemon-reload && systemctl start kubelet.service

    切换至具体的日志目录 /var/log/kubernetes,查看如下

    <root@HK-K8S-WN4 /var/log/kubernetes># ls -lrth
    total 23M
    -rw-r--r-- 1 root root  926 Aug 16 12:01 kubelet.HK-K8S-WN4.root.log.ERROR.20210816-120124.15011
    -rw-r--r-- 1 root root 1.6K Aug 16 12:01 kubelet.HK-K8S-WN4.root.log.WARNING.20210816-120117.15011
    -rw-r--r-- 1 root root  18K Aug 16 12:30 kubelet.HK-K8S-WN4.root.log.INFO.20210816-120117.15011
    lrwxrwxrwx 1 root root   54 Aug 16 12:30 kubelet.INFO -> kubelet.HK-K8S-WN4.root.log.INFO.20210816-123000.23141
    lrwxrwxrwx 1 root root   57 Aug 16 12:30 kubelet.WARNING -> kubelet.HK-K8S-WN4.root.log.WARNING.20210816-123001.23141
    lrwxrwxrwx 1 root root   55 Aug 16 12:30 kubelet.ERROR -> kubelet.HK-K8S-WN4.root.log.ERROR.20210816-123007.23141
    -rw-r--r-- 1 root root  926 Aug 16 12:30 kubelet.HK-K8S-WN4.root.log.ERROR.20210816-123007.23141
    -rw-r--r-- 1 root root 1.6K Aug 16 12:30 kubelet.HK-K8S-WN4.root.log.WARNING.20210816-123001.23141
    -rw-r--r-- 1 root root  23M Aug 16 14:24 kubelet.HK-K8S-WN4.root.log.INFO.20210816-123000.23141

 

 

 

posted @ 2021-08-16 14:25  MacoPlus  阅读(6437)  评论(0编辑  收藏  举报