Identify the container name in the ubi9-command pod with the oc get command. Specify the JSON format for the command output. Parse the JSON output with the jq command to retrieve the value of the .status.containerStatuses[].name object.
[student@workstation ~]$ oc get pod ubi9-command -o json | \
jq .status.containerStatuses[].name
"ubi9-command"
The ubi9-command pod has a single container of the same name.
Find the host node for the ubi9-command pod. Start a debug pod for the host with the oc debug command.
[student@workstation ~]$ oc get pods ubi9-command -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ubi9-command 1/1 Running 2 (16m ago) 27m 10.8.0.26 master01 <none> <none>
[student@workstation ~]$ oc debug node/master01
Error from server (Forbidden): nodes "master01" is forbidden: User "developer" cannot get resource "nodes" in API group "" at the cluster scope
The debug pod fails because the developer user does not have the required permission to debug a host node.
Log in as the admin user with the redhatocp password. Start a debug pod for the host with the oc debug command. After connecting to the debug pod, run the chroot /host command to use host binaries, such as the crictl command-line tool.
[student@workstation ~]$ oc login -u admin -p redhatocp
Login successful.
...output omitted...
[student@workstation ~]$ oc debug node/master01
Starting pod/master01-debug ...
To use host binaries, run `chroot /host`
Pod IP: 192.168.50.10
If you don't see a command prompt, try pressing enter
sh-4.4# chroot /host
Use the crictl ps command to retrieve the ubi9-command container ID. Specify the ubi9-command container with the --name option and use the JSON output format. Parse the JSON output with the jq -r command to get the RAW JSON output. Export the container ID as the $CID environment variable.
NOTE
When using jq without the -r flag, the container ID is wrapped in double quotes, which does not work with crictl commands. If the -r flag is not used, then you can add | tr -d '"' to the end of the command to trim the double quotes.
sh-4.4# crictl ps --name ubi9-command -o json | jq -r .containers[0].id
81adbc6222d79ed9ba195af4e9d36309c18bb71bc04b2e8b5612be632220e0d6
sh-4.4# CID=$(crictl ps --name ubi9-command -o json | jq -r .containers[0].id)
sh-4.4# echo $CID
81adbc6222d79ed9ba195af4e9d36309c18bb71bc04b2e8b5612be632220e0d6
Your container ID value might differ from the previous output.
The crictl ps command works with container IDs, container names, and pod IDs, but not with pod names. Execute the crictl pods command to retrieve the pod ID of the master01-debug pod. Next, use the crictl ps command and the pod ID to retrieve the master01-debug pod container name. Then, use the crictl ps command and the container name to retrieve the container ID. Save the debug container ID as the $DCID environment variable.
sh-4.4# crictl pods --name master01-debug
POD ID CREATED STATE NAME NAMESPACE ATTEMPT RUNTIME
cb066ee76b598 34 minutes ago Ready master01-debug openshift-debug-bh7kn 0 (default)
sh-4.4# crictl ps -p cb066ee76b598 -o json | jq -r .containers[0].metadata.name
container-00
sh-4.4# crictl ps --name container-00 -o json | jq -r .containers[0].id
094f93339adc7d4053ede708c78be4dc155959ea78ebabe9573365b04cfa12f2
sh-4.4# DCID=$(crictl ps --name container-00 -o json | jq -r .containers[0].id)
Your pod ID and container ID values might differ from the previous output.
Use the crictl inspect command to find the PID of the ubi9-command container and the container-00 container. The PID value is in the .info.pid object in the crictl inspect output. Export the ubi9-command container PID as the $PID environment variable. Export the container-00 container PID as the $DPID environment variable.
sh-4.4# crictl inspect $CID | grep pid
"pid": 365297,
"pids": {
"type": "pid"
...output omitted...
}
...output omitted...
sh-4.4# PID=365297
sh-4.4# crictl inspect -o json $DCID | jq .info.pid
151115
sh-4.4# DPID=151115
Your PID values might differ from the previous output.