OpenShift Container Platform leverages the Kubernetes concept of a Pod, which is one or more containers deployed together on one host. A Pod is the smallest compute unit that can be defined, deployed, and managed on OpenShift Container Platform 4.5.

After a Pod is defined, it is assigned to run on a node until its containers exit, or until it is removed. Depending on policy and exit code, Pods are either removed after exiting or retained so that their logs can be accessed.

The first thing to check when Pod issues arise is the Pod’s status. If an explicit Pod failure has occurred, observe the Pod’s error state to identify specific image, container, or Pod network issues. Focus diagnostic data collection according to the error state. Review Pod event messages, as well as Pod and container log information. Diagnose issues dynamically by accessing running Pods on the command line, or start a debug Pod with root access based on a problematic Pod’s deployment configuration.

Understanding Pod error states

Pod failures return explicit error states that can be observed in the status field in the output of oc get Pods. Pod error states cover image, container, and container network related failures.

The following table provides a list of Pod error states along with their descriptions.

Table 1. Pod error states
Pod error state Description

ErrImagePull

Generic image retrieval error.

ErrImagePullBackOff

Image retrieval failed and is backed off.

ErrInvalidImageName

The specified image name was invalid.

ErrImageInspect

Image inspection did not succeed.

ErrImageNeverPull

PullPolicy is set to NeverPullImage and the target image is not present locally on the host.

ErrRegistryUnavailable

When attempting to retrieve an image from a registry, an HTTP error was encountered.

ErrContainerNotFound

The specified container is either not present or not managed by the kubelet, within the declared Pod.

ErrRunInitContainer

Container initialization failed.

ErrRunContainer

None of the Pod’s containers started successfully.

ErrKillContainer

None of the Pod’s containers were killed successfully.

ErrCrashLoopBackOff

A container has terminated. The kubelet will not attempt to restart it.

ErrVerifyNonRoot

A container or image attempted to run with root privileges.

ErrCreatePodSandbox

Pod sandbox creation did not succeed.

ErrConfigPodSandbox

Pod sandbox configuration was not obtained.

ErrKillPodSandbox

A Pod’s sandbox did not stop successfully.

ErrSetupNetwork

Network initialization failed.

ErrTeardownNetwork

Network termination failed.

Reviewing Pod status

You can query Pod status and error states. You can also query a Pod’s associated deployment configuration and review base image availability.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • You have installed the OpenShift CLI (oc).

  • skopeo is installed.

Procedure
  1. Switch into a project:

    $ oc project <project_name>
  2. List Pods running within the namespace, as well as Pod status, error states, restarts, and age:

    $ oc get pods
  3. Determine whether the namespace is managed by a deployment configuration:

    $ oc status

    If the namespace is managed by a deployment configuration, the output includes the deployment configuration name and a base image reference.

  4. Inspect the base image referenced in the preceding command’s output:

    $ skopeo inspect docker://<image_reference>
  5. If the base image reference is not correct, update the reference in the deployment configuration:

    $ oc edit deployment/my-deployment
  6. When deployment configuration changes on exit, the configuration will automatically redeploy. Watch Pod status as the deployment progresses, to determine whether the issue has been resolved:

    $ oc get pods -w
  7. Review events within the namespace for diagnostic information relating to Pod failures:

    $ oc get events

Inspecting Pod and container logs

You can inspect Pod and container logs for warnings and error messages related to explicit Pod failures. Depending on policy and exit code, Pod and container logs remain available after Pods have been terminated.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • Your API service is still functional.

  • You have installed the OpenShift CLI (oc).

Procedure
  1. Query logs for a specific Pod:

    $ oc logs <pod_name>
  2. Query logs for a specific container within a Pod:

    $ oc logs <pod_name> -c <container_name>

    Logs retrieved using the preceding oc logs commands are composed of messages sent to stdout within Pods or containers.

  3. Inspect logs contained in /var/log/ within a Pod.

    1. List log files and subdirectories contained in /var/log within a Pod:

      $ oc exec <pod_name> ls -alh /var/log
    2. Query a specific log file contained in /var/log within a Pod:

      $ oc exec <pod_name> cat /var/log/<path_to_log>
    3. List log files and subdirectories contained in /var/log within a specific container:

      $ oc exec <pod_name> -c <container_name> ls /var/log
    4. Query a specific log file contained in /var/log within a specific container:

      $ oc exec <pod_name> -c <container_name> cat /var/log/<path_to_log>

Accessing running Pods

You can review running Pods dynamically by opening a shell inside a Pod or by gaining network access through port forwarding.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • Your API service is still functional.

  • You have installed the OpenShift CLI (oc).

Procedure
  1. Switch into the project that contains the Pod you would like to access. This is necessary because the oc rsh command does not accept the -n namespace option:

    $ oc project <namespace>
  2. Start a remote shell into a Pod:

    $ oc rsh <pod_name>  (1)
    1 If a Pod has multiple containers, oc rsh defaults to the first container unless -c <container_name> is specified.
  3. Start a remote shell into a specific container within a Pod:

    $ oc rsh -c <container_name> pod/<pod_name>
  4. Create a port forwarding session to a port on a Pod:

    $ oc port-forward <pod_name> <host_port>:<pod_port>  (1)
    1 Enter Ctrl+C to cancel the port forwarding session.

Starting debug Pods with root access

You can start a debug Pod with root access, based on a problematic Pod’s deployment or deployment configuration. Pod users typically run with non-root privileges, but running troubleshooting Pods with temporary root privileges can be useful during issue investigation.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • Your API service is still functional.

  • You have installed the OpenShift CLI (oc).

Procedure
  1. Start a debug Pod with root access, based on a deployment.

    1. Obtain a project’s deployment name:

      $ oc get deployment -n <project_name>
    2. Start a debug Pod with root privileges, based on the deployment:

      $ oc debug deployment/my-deployment --as-root -n <project_name>
  2. Start a debug Pod with root access, based on a deployment configuration.

    1. Obtain a project’s deployment configuration name:

      $ oc get deploymentconfigs -n <project_name>
    2. Start a debug Pod with root privileges, based on the deployment configuration:

      $ oc debug deploymentconfig/my-deployment-configuration --as-root -n <project_name>

You can append -- <command> to the preceding oc debug commands to run individual commands within a debug Pod, instead of running an interactive shell.

Copying files to and from Pods and containers

You can copy files to and from a Pod to test configuration changes or gather diagnostic information.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • Your API service is still functional.

  • You have installed the OpenShift CLI (oc).

Procedure
  1. Copy a file to a Pod:

    $ oc cp <local_path> <pod_name>:/<path> -c <container_name>  (1)
    1 Note that a Pod’s first container will be selected if the -c option is not specified.
  2. Copy a file from a Pod:

    $ oc cp <pod_name>:/<path>  -c <container_name><local_path>  (1)
    1 Note that a Pod’s first container will be selected if the -c option is not specified.

    For oc cp to function, the tar binary must be available within the container.