OpenShift Series

🛠️ A "Top 1%" Hands-On Lab: Running a Container Application on OpenShift Local

Introduction

This article is part of the Top 1% Series’ full article guide, and the second article in the OpenShift Series.

Prerequisites

Prerequisites for This Hands-On Lab

Step 0: Setting Up OpenShift Local

Registering an Account and Obtaining a Pull Secret

Create a free account on Red Hat’s Developer site, and download the pull secret for your environment from OpenShift Local’s download page ahead of time.

Installing and Setting Up OpenShift Local

# After extracting the downloaded executable, place it somewhere in your PATH, then:
crc setup

crc setup prepares the virtualization environment OpenShift Local needs to run (checking the hypervisor, configuring networking, and so on). Once it completes, start the cluster.

crc start --pull-secret-file /path/to/pull-secret.txt

This command actually starts a single-node OpenShift cluster as a local virtual machine. The first run takes anywhere from a few to over ten minutes. Once it completes, it displays the information (a URL and initial password) you need to log into the cluster.

Step 1: Logging Into the Web Console and the oc CLI

Visiting the URL displayed after crc start completes, in your browser, lets you log into OpenShift’s web console. Also log in via oc (the OpenShift CLI), used for command-line operations.

# Run the exact command shown in crc start's output (example)
oc login -u developer -p developer https://api.crc.testing:6443
# Check the current login state / connected cluster
oc whoami
oc project

Step 2: Deploying a Sample Application (Source-to-Image)

Here you’ll actually experience the Source-to-Image (S2I) mechanism covered in Understanding What OpenShift Actually Is From a “Top 1%” Perspective. This uses a publicly available sample Node.js application repository as an example.

# Create a new working Project (Namespace)
oc new-project handson-demo

# Just specifying a Git repository automatically selects the build image,
# building and deploying the application's image from source code
oc new-app nodejs~https://github.com/sclorg/nodejs-ex.git --name=hello-node

Running oc new-app makes OpenShift detect the content of the specified Git repository (in this case, that it’s a Node.js application) and automatically starts a build using the corresponding builder image. You can check the build’s progress with the following commands.

# Check the build's progress in real time
oc logs -f bc/hello-node

# Check whether the Pod has actually started
oc get pods

If you see a Pod with STATUS showing Running, the application deployment succeeded.

Step 3: Exposing the Application Externally With a Route

By default, the deployed application is only accessible from within the cluster. Create a Route, covered in Understanding What OpenShift Actually Is From a “Top 1%” Perspective, to make it accessible from outside.

# Create a Route for the Service, assigning it a hostname for external access
oc expose service/hello-node

# Check the assigned hostname
oc get route hello-node

Visiting the displayed hostname in your browser shows the sample application’s screen. Try confirming that this Route’s creation, just like the binding configuration covered in Understanding How IIS and ASP.NET Work from a “Top 1%” Perspective, routes external requests to a specific application based on hostname.

Step 4: Experiencing Scaling (Changing the Replica Count)

Here you’ll experience declarative replica-count management via a Deployment, one of Kubernetes’s and OpenShift’s core characteristics.

# Check the current Pod count (usually 1)
oc get pods

# Change the replica count to 3
oc scale deployment/hello-node --replicas=3

# After a few seconds, confirm the Pod count has grown to 3
oc get pods

You’ll see the behavior where the actual Pod count is automatically adjusted to match the specified replica count (3). As a test, try manually deleting one of the Pods.

# Check the Pod names, then delete one of them
oc delete pod <pod-name>

# Wait a moment and check again — a new Pod gets automatically
# replenished, always maintaining a count of 3
oc get pods

This behavior — automatically maintaining the actual state to always match the declared state — is the core design philosophy of Kubernetes and OpenShift.

Step 5: Cleaning Up

Once you’re done testing, delete the Project you created, and stop and delete the cluster itself.

# Delete the Project you created (all resources within it are deleted too)
oc delete project handson-demo

# Stop the cluster (you can resume it next time with crc start)
crc stop

# To completely delete the cluster
crc delete

Common Errors and How to Handle Them

Summary

What to Keep in Mind From Today

  1. Always run a state-checking command like oc get pods before and after an operation, and build the habit of visually confirming the change.
  2. Experience the idea of declarative state management by watching a new Pod get automatically replenished even after you manually delete one.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).