Outcomes
Investigate errors with creating a pod.
View the status, logs, and events for a pod.
Copy files into a running pod.
Connect to a running pod by using port forwarding.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that the cluster and all exercise resources are available.
[student@workstation ~]$ lab start pods-troubleshooting
Instructions
Log in to the OpenShift cluster and create the
pods-troubleshootingproject.Log in to the OpenShift cluster as the
developeruser with theoccommand.[student@workstation ~]$
oc login -u developer -p developer \ https://api.ocp4.example.com:6443...output omitted...Create the
pods-troubleshootingproject.[student@workstation ~]$
oc new-project pods-troubleshooting...output omitted...
Create a MySQL pod called
mysql-serverwith theoc runcommand. Use theregistry.ocp4.example.com:8443/rhel9/mysql-80:1228container image for the pod. Specify the environment variables with the following values:Variable Value MYSQL_USERredhatMYSQL_PASSWORDredhat123MYSQL_DATABASEworldThen, view the status of the pod with the
oc getcommand.Create the
mysql-serverpod with theoc runcommand. Specify the environment values with the--envoption.[student@workstation ~]$
oc run mysql-server \ --image registry.ocp4.example.com:8443/rhel9/mysql-80:1228 \ --env MYSQL_USER=redhat \ --env MYSQL_PASSWORD=redhat123 \ --env MYSQL_DATABASE=worldpod/mysql createdAfter a few moments, retrieve the status of the pod. Execute the
oc get podscommand a few times to view the status updates for the pod.[student@workstation ~]$
oc get podsNAME READY STATUS RESTARTS AGE mysql-server 0/1 ErrImagePull 0 30s[studet@workstation ~]$
oc get podsNAME READY STATUS RESTARTS AGE mysql-server 0/1 ImagePullBackoff 0 45sThe pod failed to start.
Identify the root cause of the pod's failure.
Retrieve the pod's logs with the
oc logscommand.[student@workstation ~]$
oc logs mysql-serverError from server (BadRequest): container "mysql-server" in pod "mysql-server" is waiting to start: trying and failing to pull imageThe logs state that the pod cannot pull the container image.
Retrieve the events log with the
oc get eventscommand.student@workstation ~]$
oc get eventsLAST SEEN TYPE REASON OBJECT MESSAGE 33s Normal Scheduled pod/mysql-server Successfully assigned pods-troubleshooting/mysql-server to master01 by master01 31s Normal AddedInterface pod/mysql-server Add eth0 [10.8.0.68/23] from ovn-kubernetes 16s Normal Pulling pod/mysql-server Pulling image "registry.ocp4.example.com:8443/rhel9/mysql-80:1228" 16s Warning Failed pod/mysql-serverFailed to pull image "registry.ocp4.example.com:8443/rhel9/mysql-80:1228": rpc error: code = Unknown desc = reading manifest 1228 in registry.ocp4.example.com:8443/rhel9/mysql-80: manifest unknown: manifest unknown16s Warning Failed pod/mysql-server Error: ErrImagePull 4s Normal BackOff pod/mysql-server Back-off pulling image "registry.ocp4.example.com:8443/rhel9/mysql-80:1228" 4s Warning Failed pod/mysql-server Error: ImagePullBackOffThe output states that the image pull failed because the
1228manifest is unknown. This failure could mean that the manifest, or image tag, does not exist in the repository.Inspect the available manifest in the
registry.ocp4.example.com:8443/rhel9/mysql-80container repository. Authenticate to the container repository with theskopeo logincommand as thedeveloperuser with thedeveloperpassword. Then, use theskopeo inspectcommand to retrieve the available manifests in theregistry.ocp4.example.com:8443/rhel9/mysql-80repository.[student@workstation ~]$
skopeo login registry.ocp4.example.com:8443Username:developerPassword:developerLogin Succeeded![student@workstation ~]$
skopeo inspect \ docker://registry.ocp4.example.com:8443/rhel9/mysql-80...output omitted... "Name": "registry.ocp4.example.com:8443/rhel9/mysql-80", "Digest": "sha256:d282...f38f", "RepoTags": [ "1-237", "1-228", "1-228-source", "1-224", "1-224-source", "latest", "1" ], ...output omitted...The
1228manifest, or tag, is not available in the repository, which means that theregistry.ocp4.example.com:8443/rhel9/mysql-80:1228image does not exist. However, the1-228tag does exist.
The pod failed to start because of a typing error in the image tag. Update the pod's configuration to use the
registry.ocp4.example.com:8443/rhel9/mysql-80:1-228container image. Confirm that the pod is re-created after editing the resource.Edit the pod's configuration with the
oc editcommand. Locate the.spec.containers.imageobject. Update the value to theregistry.ocp4.example.com:8443/rhel9/mysql-80:1-228container image and save the change.[student@workstation ~]$
oc edit pod/mysql-server...output omitted... apiVersion: v1 kind: Pod metadata: ...output omitted... spec: containers: - image: registry.ocp4.example.com:8443/rhel9/
mysql-80:1-228...output omitted...Verify the status of the
mysql-serverpod with theoc getcommand. The pod's status might take a few moments to update after the resource edit. Repeat theoc getcommand until the pod's status changes.[student@workstation ~]$
oc get podsNAME READY STATUS RESTARTS AGE mysql-server 1/1 Running 0 10mThe
mysql-serverpod successfully pulled the image and created the container. The pod now shows aRunningstatus.
Prepare the database on the
mysql-serverpod. Copy the~/DO180/labs/pods-troubleshooting/world_x.sqlfile to themysql-serverpod. Then, connect to the pod and execute theworld_x.sqlfile to populate theworlddatabase.Use the
oc cpcommand to copy theworld_x.sqlfile in the~/DO180/labs/pods-troubleshootingdirectory to the/tmp/directory on themysql-serverpod.[student@workstation ~]$
oc cp ~/DO180/labs/pods-troubleshooting/world_x.sql \ mysql-server:/tmp/Confirm that the
world_x.sqlfile is accessible within themysql-serverpod with theoc execcommand.[student@workstation ~]$
oc exec -it pod/mysql-server -- ls -la /tmp/total 0 drwxrwxrwx. 1 root root 22 Nov 4 14:45 . dr-xr-xr-x. 1 root root 50 Nov 4 14:34 .. -rw-rw-r--. 1 1000680000 root 558791 Nov 4 14:45 world_x.sqlConnect to the
mysql-serverpod with theoc rshcommand. Then, log in to MySQL as theredhatuser with theredhat123password.[student@workstation ~]$
oc rsh mysql-serversh-5.1$
mysql -u redhat -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g. ...output omitted... mysql>redhat123From the MySQL prompt, select the
worlddatabase. Source theworld_x.sqlscript inside the pod to initialize and populate theworlddatabase.mysql>
USE world;Database changedmysql>
SOURCE /tmp/world_x.sql;...output omitted...Execute the
SHOW TABLES;command to confirm that the database now contains tables. Then, exit the database and the pod.mysql>
SHOW TABLES;----------------- | Tables_in_test | ----------------- | city | | country | | countryinfo | | countrylanguage | ----------------- 4 rows in set (0.00 sec)mysql>
exit;Bye sh-5.1$exitexit [student@workstation ~]$
Configure port forwarding and then use the MySQL client on the
workstationmachine to connect to theworlddatabase on themysql-serverpod. Confirm that you can access data within theworlddatabase from theworkstationmachine.From the
workstationmachine, use theoc port-forwardcommand to forward the3306local port to the3306port on themysql-serverpod.[student@workstation ~]$
oc port-forward mysql-server 3306:3306Forwarding from 127.0.0.1:3306 -> 3306 Forwarding from [::1]:3306 -> 3306Open another terminal window on the
workstationmachine. Connect to theworlddatabase with the local MySQL client on theworkstationmachine. Log in as theredhatuser with theredhat123password. Specify the host as the localhost127.0.0.1IP address and use3306as the port.[student@workstation ~]$
mysql -u redhat -p -h 127.0.0.1 -P 3306Enter password:redhat123Welcome to the MySQL monitor. Commands end with ; or \g. ...output omitted... mysql>Select the
worlddatabase and execute theSHOW TABLES;command.mysql>
USE world;Database changedmysql>
SHOW TABLES;----------------- | Tables_in_test | ----------------- | city | | country | | countryinfo | | countrylanguage | ----------------- 4 rows in set (0.01 sec)Confirm that you can retrieve data from the
countrytable. Execute theSELECT COUNT(*) FROM countrycommand to retrieve the number of countries within thecountrytable.mysql>
SELECT COUNT(*) FROM country;---------- | COUNT(*) | ---------- | 239 | ---------- 1 row in set (0.01 sec)Exit the database.
mysql>
exit;Bye [student@workstation ~]$Return to the terminal that is executing the
oc port-forwardcommand. Press Ctrl+C to end the connection.[student@workstation ~]$ oc port-forward mysql-server 3306:3306 Forwarding from 127.0.0.1:3306 -> 3306 Forwarding from [::1]:3306 -> 3306 Handling connection for 3306 Handling connection for 3306
^C[student@workstation ~]$