如何使用oc命令显示OpenShift节点的日志
时间:2020-02-23 14:31:32 来源:igfitidea点击:
那么,我们现在拥有标准的第二天操作了OpenShift集群了吗?在对群集问题(例如服务故障,网络和存储问题等)进行故障排除时,检查群集节点的日志是一项正常操作。在本教程中,很好地探索了如何使用命令行工具显示OpenShift节点日志。
从OpenShift Container Platform 4.0开始,OpenShift节点基于Red Hat Enterprise Linux CoreOS(RHCOS),OKD版本使用Fedora CoreOS(FCOS)。这些操作系统运行的本地服务很少,因此需要直接访问节点以检查其状态。
显示OpenShift节点的日志
RHCOS/FCOS中的大多数系统服务都是作为容器运行的,但CRI-O容器引擎和Kubelet(作为系统单元)除外。
sh-4.4# systemctl status crio ● crio.service - Open Container Initiative Daemon Loaded: loaded (/usr/lib/systemd/system/crio.service; disabled; vendor preset: disabled) Drop-In: /etc/systemd/system/crio.service.d └─10-default-env.conf Active: active (running) since Sat 2017-03-28 10:59:50 UTC; 1h 7min ago Docs: https://github.com/cri-o/cri-o Main PID: 2937 (crio) Tasks: 42 Memory: 322.4M CPU: 5min 28.410s CGroup: /system.slice/crio.service └─2937 /usr/bin/crio --enable-metrics=true --metrics-port=9537 ..... sh-4.4# systemctl status kubelet ● kubelet.service - Kubernetes Kubelet Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/kubelet.service.d └─10-default-env.conf Active: active (running) since Sat 2017-03-28 11:00:11 UTC; 1h 7min ago Process: 3028 ExecStartPre=/bin/rm -f /var/lib/kubelet/cpu_manager_state (code=exited, status=0/SUCCESS) Process: 3026 ExecStartPre=/bin/mkdir --parents /etc/kubernetes/manifests (code=exited, status=0/SUCCESS) Main PID: 3030 (hyperkube) Tasks: 56 (limit: 26213) Memory: 241.6M CPU: 5min 7.547s CGroup: /system.slice/kubelet.service └─3030 /usr/bin/hyperkube kubelet --config=/etc/kubernetes/kubelet.conf --bootstrap-kubeconfig=/etc/kubernetes/kubeconfig --kubeconfig=/var/lib/kubelet/kubeco .....
oc adm node-logs命令可用于查看这些日志,而无需直接SSH到群集节点。语法为:
oc adm node-logs [-l LABELS] [NODE...] [flags]
上面的命令将显示节点的所有日志日志。例:
$oc adm node-logs node01.ocp.theitroad.local
要从指定单位返回日志条目,请使用-u选项:
$oc adm node-logs <node-name> -u crio
显示/var/log中节点中可用的日志:
$oc adm node-logs node01.ocp.theitroad.local --path=/ audit/ btmp chrony/ containers/ crio/ es-containers.log.pos fluentd/ glusterfs/ journal/ journal_pos.json lastlog openvswitch/ pods/ private/ samba/ sssd/ vmware-network.1.log vmware-network.2.log vmware-network.log vmware-vgauthsvc.log.0 vmware-vmsvc.1.log vmware-vmsvc.log wtmp
显示节点中路径的日志文件:
oc adm node-logs node01.ocp.theitroad.local --path=/audit/audit.log
显示所有master/worker的kubelet日志:
oc adm node-logs --role master -u kubelet oc adm node-logs --role worker -u kubelet
在/var/log的master/workers/infra节点中查看可用的日志:
oc adm node-logs --role master --path=/ oc adm node-logs --role worker --path=/ oc adm node-logs --role infra --path=/