Ocnotes 1
Ocnotes 1
For im[portingindividual resorce files by specifying the file path instead of a Check Results:
directory. oc get pods — verify replicas and pod states.
Oc apply -f ./test/service_account.yaml If we do the OC get pods command, we can see that we have two pod replicas
instead of one.
# Exporting Resources
⚖ Declarative vs Imperative Commands
Purpose:
Backup, duplicate, or share resource configurations. Approach Commands Style Description
Declarative Desired Define what you want; OpenShift
Command: oc apply -f
oc get <resource_type> <resource_name> -o yaml > [Link] (Preferred) state figures out how to achieve it.
oc create, oc delete, oc Step-by- You explicitly tell OpenShift
Imperative
Examples: patch, oc replace, oc edit step what to do.
This command retrieves the definition of the first app deployment and saves it to a Declarative (oc apply)
file named my [Link].
• Checks if the resource exists:
• oc get deployment first-app -o yaml > [Link] o If not → creates it.
• you can export other types of resources such as services, config maps, or o If yes → updates only what changed.
secrets by replacing • Ideal for Infrastructure as Code (IaC) workflows.
• oc get svc,cm,secret -o yaml • Great for GitOps and version control.
Imperative Commands
Command Description
oc get List or view resources in cluster ! 4. OpenShift Image Streams
oc describe Detailed info about a resource
oc create Create from a file or stdin new resources from yaml json maifest • OpenShift uses Image Streams instead of raw images.
oc apply Create or update declaratively • An Image Stream is:
oc delete Remove a resource from clustedr o A sequence of pointers to one or more container images.
o Acts as an abstraction layer for easier image management.
oc edit Edit resources interactively in terminal
o Can be linked to deployments for automatic updates.
oc logs View container logs • Images can come from:
oc exec Run a command inside a container o Internal registry (built into OpenShift)
o External registries (e.g., [Link], Docker Hub)
Help Command:
oc -h
' Summary • When OpenShift is installed, it automatically creates Red Hat–provided image
streams.
✅ Import: oc apply -f <file_or_dir> • These are available in the openshift project (default global project).
• All users have view access to this project.
✅ Export: oc get <type> -o yaml > [Link]
✅ Extract secrets/config maps: oc extract <resource>
✅ Modify configs: Edit YAML → oc apply -f
✅ Prefer declarative (oc apply) for consistency and automation. ! 6. Key Commands
✅ Use imperative commands for direct or quick actions.
Purpose Command Description
List all image oc get imagestreams -n Lists available image streams in the
streams openshift openshift project.
Describe a specific oc describe is imagestream Shows details like labels, annotations,
( Locating and Examining Container Images in image stream <name> -n openshift repository, tags, and image IDs.
OpenShift Get details of a oc describe image
<image_id>
Displays metadata — image ID, size,
specific image creation time, ports, env vars, etc.
! 1. Importance Downloads and extracts image
Extract image oc image extract <image> -
-path /:/local/dir contents to your local system for
contents
• As an OpenShift administrator, it’s crucial to know how to find and inspect inspection.
container images running in the cluster.
• Helps in managing and troubleshooting applications.
! 7. Inspecting Images
• oc describe provides: Notes: Projects in OpenShift
o Docker image ID
o Image size
o Creation date
! 1. What is a Project in OpenShift?
o Exposed ports
o Environment variables
o Repository source
• A project in OpenShift is a logical unit that organizes and isolates resources within a
• oc image extract:
cluster.
o Extracts file system of the image.
• Each project contains:
o Deployments
o You can explore configuration files, binaries, and app code locally.
o Pods
• Another way to examine a container image is to use the OC image Extract
o Services
command to download the image
o Routes
• contents to your local file system.
o ConfigMaps, etc.
• Running the OC image extract command will extract the file system contents
• Projects also enable access control, defining who can access and manage specific
of the specified image and
resources.
• send them to the target on your local machine once the extraction is
complete.
• Navigate to that directory and explore the images file system.
• Look for configuration files, application code, and other relevant artifacts to ! 2. Purpose of Projects
understand how the
• image is structured and what it contains. • Isolation: Keeps different applications and teams separated.
• By combining these techniques, such as listing image streams, describing • Organization: Groups related resources under one logical unit.
image and image stream details, • Access Control: Determines user permissions within the project.
• and extracting image contents for further inspection. • Resource Management: Supports quotas and limits per project.
• You can comprehensively understand the container images deployed in your
OpenShift cluster.
• That concludes our lecture on locating and examining container images in
OpenShift. ! 3. Creating a Project (CLI Method)
• Please explore the container images in your cluster and apply the techniques ✅
Step 1: Login to Cluster
covered in this demo.
oc login -u developer -p <password> [Link]
o ✅
Step 2: Create a New Project
oc new-project my-demo-project
✅ 4. Deploying an Application
!
! 9. Next Steps Step 1: Create a Simple App
oc new-app -–name=my-app –-image-openshift/hello-openshift
• Practice the commands in your own OpenShift environment.
• Explore different image streams in the openshift project. ✅• Deploys a simple "Hello OpenShift" application using the provided image.
• Next topic: Creating and Deleting Projects in OpenShift.
Step 2: Check Deployment Status
oc get pods
• Displays all resources in the current project (deployments, pods, services, etc.).
! 9. Key Takeaways
✅ Describe Project Details
oc describe project my-demo-project
• Projects are fundamental for:
o Organizing workloads
• Provides detailed information including:
o Metadata (labels, annotations) o Managing access control
o Resource quotas and limits o Isolating environments
o Events and usage stats
• You can create, inspect, and delete projects via both the CLI and Web Console.
• Deleting a project cleans up all resources within it.
• Monitoring may be limited in local clusters (like CRC/OpenShift Local).
!
✅ 7. Creating a Project (Web Console Method)
Steps:
! Notes: Examining Resources and Cluster Status in OpenShift
1. Log in to the OpenShift Web Console as developer.
2. Click Add (top-left corner).
3. Select Projects. ! 1. Importance
4. Click Create Project.
5. Enter:
• As an OpenShift administrator or developer, understanding your cluster resources
o Project Name → my-demo-project
and overall health is essential.
o Optional: Display Name & Description
• Helps in monitoring performance, troubleshooting issues, and managing
6. Click Create.
workloads efficiently.
✅ The new project appears in the Developer View.
• Gives a summary of: # Note: On OpenShift Local (CRC), monitoring operators are not installed, so metrics may
o Current project
not appear.
o Services and deployments
o Recent events or warnings
! 9. Summary
" Viewing Specific Versions
• oc get and oc describe → Examine resources.
• oc status → Check project overview. If you want logs from a specific version, specify the version number:
• oc get nodes / oc get componentstatuses → Check cluster health.
• oc adm top → Monitor resource utilization. # For a specific deployment version
• Web Console → Visual monitoring and insights. oc logs -deployment/<deployment-name> -version=<version-number>
# For a specific build version
• Regular monitoring ensures cluster stability and proactive issue resolution. oc logs bc/<build-configname> --version=< version-number>
For example, if you want to see the logs of the first deployment, you would use version equals one.
! Lesson Notes: Viewing and Analyzing Logs in # Show only the last 10 lines
oc logs -f pod/<pod_name> --tail=10 (oc logs -f pod my-pod--tail=10)
OpenShift
$ Viewing Node-Level Logs
" Introduction ! Administrator Command
oc adm node-logs <node_name>
• Logs are essential for troubleshooting, monitoring, and understanding what’s This command requires administrator level cluster permissions and will return logs
happening inside your OpenShift cluster. from the system services
• They help diagnose issues like crash loops, failed deployments, or permission running on your nodes.
errors.
• You’ll use both the CLI (oc logs) and the Web Console to access and analyze logs.
• Requires cluster-admin privileges.
• Used to fetch logs from node-level system services (e.g., kubelet, cri-o).
• The main command for retrieving logs of pods, builds, or deployments. # Only kubelet logs
• Syntax help: oc adm node-logs –role master -u kubelet
• oc logs -h
Displays available options and usage examples. % Using oc describe for Event & Log Context
oc describe pod/<pod_name>
Steps:
Identify container name (e.g., log-demo) and review details. • Logs are your best friend for debugging and learning what’s really happening inside
OpenShift.
15. Root Cause: • Think of them as a treasure map pointing you to the root cause of issues.
o NGINX is attempting to perform privileged operations. • By mastering oc logs, oc describe, and oc adm node-logs, you’ll be fully
o Container is non-root → permission issues. equipped for both real-world troubleshootingand the exam.
16. Solution:
o Modify deployment configuration to allow appropriate privileges, or
o Use a base image that doesn’t require root access.
• Nodes It's important to establish a baseline for etcd performance, and set up alerts to notify
• etcd (data store) you of any
• Operators deviations or anomalies.
• Version Compatibility
⚙ 2. Node Health
' 4. Operators Health
Nodes are the backbone of your OpenShift cluster.
They run the containers and provide CPU, memory, and network resources. Operators manage the lifecycle of OpenShift components and ensure everything stays in the
& Commands: desired state.
&
Commands:
1. List all nodes:
2. oc get nodes
1. Check operator status:
o Displays all nodes and their status. 2. oc get clusteroperators
o ✅ Ready = healthy, ❌ NotReady = issue to investigate. o Available=True ✅ means healthy.
3. Check resource usage (CPU/Memory): o Progressing=True ⏳ = update in progress.
4. oc adm top nodes
o Shows real-time node metrics. o Degraded=True ⚠ = issue detected.
o Requires metrics-server to be running. 3. Inspect degraded operatorLwe can use oc log)
4. oc describe clusteroperator <operator-name>
5. Inspect specific node details: 5. oc logs -n <operator-namespace> <operator-pod>
6. oc describe node <node-name>
o Check for related error messages.
o Shows:
§ Allocated resources
§ Conditions
§ Recent events
( 5. Version Checks
§ Non-terminated pods
• Regularly check node, etcd, and operator health. → Check Events section for messages like:
• Use logs and metrics to identify early issues.
• Always ensure version compatibility. o Failed to pull image
• Healthy cluster = reliable application performance. o CrashLoopBackOff
Back-off restarting container Pay attention to the exit codes and error messages to
identify the root cause of the issue.
For example, an event like failed to pull image indicates that the container image specified in
the
pod configuration could not be retrieved from the registry.
o
) Lecture Notes: Troubleshooting Common Container, Pod, and 5. If image pull fails:
Cluster Events & Alerts in OpenShift o Verify image name, tag, and registry access.
# Objective
+ Issue 2: Exceeding Resource Limits
Learn to identify, analyze, and troubleshoot common container, pod, and cluster-level issues
in OpenShift using logs, events, and commands.
• If CPU/memory limits are exceeded, container may throttle or terminate.
Commands:
• "0/1 nodes are available: insufficient CPU." • etcd stores all cluster configuration and state data.
• "node(s) didn’t match node selector" • Problems can cause cluster instability.
Commands:
+ Issue 2: Pod Evicted or Terminated Repeatedly For example, you can use etcd CTL endpoint health to check the health of etcd
members and identify
Causes: any problematic nodes.
Fix:
Possible causes:
• Misconfigured network policies 6. Describe pod for details:
• Firewall restrictions 7. oc describe pod <pod-name>
• Network plugin failure
Event Output:
Steps:
0/1 nodes are available: node(s) didn’t match node selector.
1. Inspect Pod Network Details:
2. oc describe pod <pod-name> } Look for any error messages or indications of network 8. Label the node: Let's add the node name equals CRC label to our node to
related problems. resolve this.
3. Check connectivity between pods: 9. oc label node crc nodeName=crc
4. oc exec -it <pod-1> -- ping <pod-2-IP> 10. Check pod again:
5. Additionally, you can use network diagnostic tools like ping, traceroute or 11. oc get pods
telnet to test connectivity
6. between pods or external endpoints. : oc exec my-pod –ping another-pod → Pod now shows Running ✅
7.
8. Use tools like: Oc describe pod nginx
o traceroute
o telnet
o curl
9. Verify network policies:
10. oc get networkpolicy -A $ Lesson Takeaways
Issue Type Useful Commands Fix
Container crash oc logs, oc describe pod Check logs, fix image/config
- 5. Demo: Troubleshooting Pod Scheduling (NodeSelector Example)
Resource limit oc adm top pods Adjust limits
- Scenario Pod pending oc describe pod Fix selector / resources
Pod evicted oc get events Add resources, check node
A new app is created with a nodeSelector condition, but no node matches it → Pod remains etcd issues etcdctl endpoint health Monitor health, logs
in Pending state.
Network issues oc exec ping, oc describe Fix network policies
( 1. Importance of Documentation
⚙ 4. Example: Creating and Deploying an Application
As an OpenShift administrator, the official product documentation is your go-to guide for:
$ Step 1: Create a New Project
• Understanding platform features
• Learning installation, configuration, and management • Go to the Developer Activities section
• Troubleshooting issues • Locate Work with Projects → Open it in a new tab
• Exploring best practices and new capabilities • Follow the guide to:
o Create a new project (Web Console or CLI)
% The documentation is continuously updated with every new release. o Set access permissions
o View or delete projects
( 7. Summary
Key Area Description
Access Docs [Link]
Navigation Choose version → explore categories
CLI Support Use oc help, oc explain, and oc version
Hands-on Follow step-by-step examples and YAML snippets
Continuous Learning Check documentation regularly for updates
✅ Takeaway