How to display logs of OpenShift nodes using oc command

Ranch
You can support us by downloading this article in PDF format via the link below.

Download the guide as a PDF

turn off
Ranch

Ranch
Ranch

Now that you have an OpenShift cluster, can you now do standard day 2 operations? When troubleshooting cluster issues such as service failures, network and storage issues, etc., checking the logs of the cluster nodes is a normal operation. In this guide, we will explore how to display OpenShift node logs using a command line tool.

Starting with OpenShift Container Platform 4.0, OpenShift nodes are based on Red Hat Enterprise Linux CoreOS (RHCOS), and OKD versions use Fedora CoreOS (FCOS). These operating systems run very few local services and therefore require direct access to the node to check its status.

Display logs of OpenShift nodes

Most system services in RHCOS / FCOS run as containers, with the exception of the CRI-O container engine and Kubelet (as a system unit).

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 2020-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 2020-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
.....

of oc adm node log This command can be used to view these logs without having to ssh directly to the cluster nodes. The syntax is:

oc adm node-logs [-l LABELS] [NODE...] [flags]

The above command will display all log logs for the node. example:

$ oc adm node-logs node01.ocp.computingforgeeks.com

To return log entries from the specified unit, use -u Options:

$ oc adm node-logs  -u crio

Show the logs available in the node in / var / log:

$ oc adm node-logs node01.ocp.computingforgeeks.com --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

Display log files for paths in the node:

oc adm node-logs node01.ocp.computingforgeeks.com --path=/audit/audit.log

Show kubelet logs for all masters / workers:

oc adm node-logs --role master -u kubelet
oc adm node-logs --role worker -u kubelet

Check the available logs in the master / workers / infra node of / var / log:

oc adm node-logs --role master --path=/
oc adm node-logs --role worker --path=/
oc adm node-logs --role infra --path=/

More articles about the OpenShift container platform:

How to open a shell prompt on an OpenShift node

Prevent users from creating projects in OpenShift / OKD clusters

How to install Operator SDK CLI on Linux / macOS

Set up a local OpenShift cluster with a CodeReady container

Ranch
You can support us by downloading this article in PDF format via the link below.

Download the guide as a PDF

turn off
Ranch

Ranch
Ranch

Related Posts