Inspecting logs demonstration in OpenShift

Login as developer:

oc login -u developer -p developer
Create a project:
oc new-project log-demo
Create a new app:
oc new-app --name=log-demo --docker-image=nginx
Check the pod status:
oc get po
NAME                        READY   STATUS             RESTARTS      AGE
log-demo-76d49479f6-ghddz   0/1     CrashLoopBackOff   2 (22s ago)   48s
It looks that our pod isn’t running. It is stuck in CrashLoopBackOff state - which indicates something is not quite right with the container.

That’s where logs come to the rescue:
oc logs -f log-demo-76d49479f6-ghddz
We have some error messages related to innability to write to some specific directories:
2024/12/28 19:03:51 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
If we want to have more specific information - we can try to get the container logs. First, find the container name:
oc describe po log-demo-76d49479f6-ghddz
Look in the Containers section:
...
Containers:
  log-demo:
...
this container name is log-demo. Armed with this information we can ise the container name to view its logs:
oc logs -f log-demo-76d49479f6-ghddz -c log-demo
We are gettting something like this:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/12/28 19:08:05 [warn] 1#1: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
2024/12/28 19:08:05 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
nginx tries to make directories and modify files, but it does not have required permissions since it is running as non-root user - which is default for most containers on OpenShift. We must grant the necessary permissions to the pods in the deployment or to switch and use another container image which does not require a root privileges.

The same logs can be seen in the GUI: login as developer, navigate to project, select the pod, and switch to the Logs tab