欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kubernetes 查看pod 对应的容器日志

程序员文章站 2024-03-11 19:13:13
...

1.pod若处于运行状态,则通过kubectl logs 即可

[[email protected] ~]# kubectl logs node-exporter-2f5ll -c node-exporter -n openstack
time="2019-06-26T01:00:30Z" level=info msg="Starting node_exporter (version=0.15.0, branch=HEAD, revision=6e2053c557f96efb63aef3691f15335a70baaffd)" source="node_exporter.go:43"
time="2019-06-26T01:00:30Z" level=info msg="Build context (go=go1.9.1, [email protected], date=20171006-11:33:58)" source="node_exporter.go:44"
time="2019-06-26T01:00:30Z" level=info msg="Enabled collectors:" source="node_exporter.go:50"
time="2019-06-26T01:00:30Z" level=info msg=" - ipvs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - arp" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - xfs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - bcache" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - mountstats" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - stat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - timex" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - netdev" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - netstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - diskstats" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - zfs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - textfile" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - uname" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - hwmon" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - cpu" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - loadavg" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - meminfo" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - conntrack" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - edac" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - infiniband" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - filefd" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - time" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - mdadm" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - sockstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - filesystem" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - vmstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - entropy" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - wifi" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg="Listening on :9100" source="node_exporter.go:76"
time="2019-06-26T01:24:50Z" level=error msg="ERROR: xfs collector failed after 0.027436s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-63/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-27T11:00:12Z" level=error msg="ERROR: xfs collector failed after 0.418834s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-149/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T02:37:34Z" level=error msg="ERROR: xfs collector failed after 0.187959s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-27/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T06:41:01Z" level=error msg="ERROR: xfs collector failed after 0.039895s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-36/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T06:50:34Z" level=error msg="ERROR: xfs collector failed after 0.038196s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-206/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T07:18:53Z" level=error msg="ERROR: xfs collector failed after 0.036079s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-78/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T07:54:27Z" level=error msg="ERROR: xfs collector failed after 0.027663s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-190/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T11:34:29Z" level=error msg="ERROR: xfs collector failed after 0.027551s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-128/stats/stats: no such file or directory" source="collector.go:123"

2.若pod处于init状态,则需要通过docker ps查看

(1) 获取对应的pod name

[[email protected] ~]# kubectl get pods -n openstack -o wide | grep node-exporter | grep node-1
node-exporter-2f5ll                              5/5       Running   0          3d        10.20.0.4      node-1

(2) 通过docker ps 获取该pod的中的CONTAINER ID

[[email protected] ~]# docker ps | grep node-exporter-2f5ll
ba0c7a3d5c41        hub.easystack.io/production/[email protected]:46319b571ca730b7df926dd630bff5060e587694a6321e360016c1785840d98b                                        "/ipmi_exporter"         3 days ago          Up 3 days                               k8s_ipmi-exporter_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0
039d4f45d537        hub.easystack.io/production/[email protected]:d25907f8486f1914fa8f94a924c7723d09cd93b226bb4759d9e47b4322805b09                   "/tmp/eventmonitor..."   3 days ago          Up 3 days                               k8s_event-monitor_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0
5e250c413ba6        hub.easystack.io/production/[email protected]:dd6e26d988996ca6ba42945dcf540dfeb15c71bd64ebe7c881db197452cb1486                         "/tmp/cronjob.sh"        3 days ago          Up 3 days                               k8s_node-script-collector_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0
9092785e81f0        hub.easystack.io/production/[email protected]:10849369c5567a44e19cffeeb6b12cdfa45c52448ee10d824863b9f0b8094bf1                                   "/opt/node-exporte..."   3 days ago          Up 3 days                               k8s_smartmon-collector_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0
ff245b8e8e08        hub.easystack.io/production/[email protected]:57d9b335b593e4d0da1477d7c5c05f23d9c3dc6023b3e733deb627076d4596ed                                        "/bin/node_exporte..."   3 days ago          Up 3 days                               k8s_node-exporter_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0
46ffa8f3d0c9        hub.easystack.io/captain/pause-amd64:3.0                                                                                                                 "/pause"                 3 days ago          Up 3 days                               k8s_POD_node-exporter-2f5ll_openstack_18ccaaf8-97ad-11e9-a253-fa163e801c84_0

(3) 通过docker log获取对应的日志信息

[[email protected] ~]# docker logs ff245b8e8e08
time="2019-06-26T01:00:30Z" level=info msg="Starting node_exporter (version=0.15.0, branch=HEAD, revision=6e2053c557f96efb63aef3691f15335a70baaffd)" source="node_exporter.go:43"
time="2019-06-26T01:00:30Z" level=info msg="Build context (go=go1.9.1, [email protected], date=20171006-11:33:58)" source="node_exporter.go:44"
time="2019-06-26T01:00:30Z" level=info msg="Enabled collectors:" source="node_exporter.go:50"
time="2019-06-26T01:00:30Z" level=info msg=" - ipvs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - arp" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - xfs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - bcache" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - mountstats" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - stat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - timex" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - netdev" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - netstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - diskstats" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - zfs" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - textfile" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - uname" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - hwmon" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - cpu" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - loadavg" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - meminfo" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - conntrack" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - edac" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - infiniband" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - filefd" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - time" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - mdadm" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - sockstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - filesystem" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - vmstat" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - entropy" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg=" - wifi" source="node_exporter.go:52"
time="2019-06-26T01:00:30Z" level=info msg="Listening on :9100" source="node_exporter.go:76"
time="2019-06-26T01:24:50Z" level=error msg="ERROR: xfs collector failed after 0.027436s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-63/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-27T11:00:12Z" level=error msg="ERROR: xfs collector failed after 0.418834s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-149/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T02:37:34Z" level=error msg="ERROR: xfs collector failed after 0.187959s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-27/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T06:41:01Z" level=error msg="ERROR: xfs collector failed after 0.039895s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-36/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T06:50:34Z" level=error msg="ERROR: xfs collector failed after 0.038196s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-206/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T07:18:53Z" level=error msg="ERROR: xfs collector failed after 0.036079s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-78/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T07:54:27Z" level=error msg="ERROR: xfs collector failed after 0.027663s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-190/stats/stats: no such file or directory" source="collector.go:123"
time="2019-06-28T11:34:29Z" level=error msg="ERROR: xfs collector failed after 0.027551s: failed to retrieve XFS stats: open /sys/fs/xfs/dm-128/stats/stats: no such file or directory" source="collector.go:123"

当然,以上示例是运行正常的容器日志