Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

What is Openshift S2I?


🎯 What is S2I?

S2I = Source-to-Image

βœ… It’s a build process invented by OpenShift (Red Hat) to automate:

“Take my source code + take a base image β†’ and build a new runnable application container.”

You give it:

  • Source code (like HTML, PHP, Python app, Java code)
  • S2I base image (like nginx, nodejs, python builder image)

It gives you:

  • New container image that has both the code + runtime server inside.

πŸ“¦ What is an S2I Base Image?

An S2I base image is a special Docker container image that:

FeatureDescription
Has a web server, app server, or runtime pre-installede.g., nginx, nodejs, python
Has scripts inside (assemble, run)Helps OpenShift build a new app image automatically
Waits for your source codeYour app code is injected during build
Produces a new runnable imageCombining base + your code

βœ… S2I base images are made specially for OpenShift pipelines.

They are not meant to be directly run without building first.


🧠 Easy Example:

Imagine you want to deploy a static website:

Traditional WayS2I Way
You manually build Docker image (nginx + your site files)You push your HTML files to GitHub
You write Dockerfile yourselfOpenShift runs oc new-app nginx-s2i~your-git-repo
You manually build/push containerOpenShift builds everything automatically

βœ… Less work for you βœ… More automation for you


πŸ“’ Example of S2I base images:

Base ImageLanguage/RuntimeUsage
registry.redhat.io/rhscl/nginx-116-rhel7nginxServe HTML sites
registry.redhat.io/rhscl/nodejs-14-rhel7Node.js 14Node.js apps
registry.redhat.io/rhscl/python-38-rhel7Python 3.8Python apps
registry.redhat.io/rhscl/php-73-rhel7PHP 7.3PHP apps

All these are S2I base images.


πŸ“‹ How an S2I base image actually works inside:

It includes scripts like:

ScriptPurpose
assembleHow to copy your source code into the container and prepare the app
runHow to start the server when container runs
save-artifactsOptional, to cache dependencies

βœ… OpenShift uses these scripts automatically when you run oc new-app.

You don’t have to write Dockerfiles manually!


πŸš€ S2I Full Flow (Visual)

Your GitHub Repo (HTML / PHP / Python App)
          ↓
+-------------------+
|  S2I Base Image    |
| (nginx, python)    |
+-------------------+
          ↓
OpenShift S2I Process (BuildConfig)
          ↓
New Image (runtime + your code together)
          ↓
Pod runs your application!

πŸ”₯ When to use S2I

Use S2I if…Reason
You have app source code (HTML, PHP, Node.js, Python, etc.)Easy auto-build
You don’t want to write Dockerfiles manuallySaves your time
You want to build and deploy faster inside OpenShiftAutomated pipelines

βœ… S2I is powerful especially for development workflows and CI/CD pipelines.


✨ In one simple sentence:

S2I Base Image is a starting point container that expects your source code and creates a ready-to-run application image automatically inside OpenShift.


πŸ›  Summary Table:

TermMeaning
S2ISource-to-Image build process
S2I Base ImagePre-built image waiting for your code
Used forAutomating app builds inside OpenShift
Needs Source Code?βœ… Yes
Runs directly as pod?❌ No, needs build step first

πŸš€ Practical Tip for You

ScenarioWhat to use
Want to run simple nginx server quicklyUse nginxinc/nginx-unprivileged
Want to build HTML app and serveUse rhscl/nginx-116-rhel7 as S2I

🎯 Running an S2I Base Image in OpenShift Cluster

βœ… Beginner-friendly
βœ… Realistic example
βœ… Works on OpenShift 4.x or later


πŸ“¦ S2I Tutorial Overview

We will:

StepTaskDescription
1Pick an S2I base imageExample: registry.redhat.io/rhscl/nginx-116-rhel7
2Prepare simple source codeHTML project on GitHub
3Create S2I app in OpenShiftUsing oc new-app
4Deploy and access appVia OpenShift Route

πŸ›  Step 1: Pick an S2I Base Image

We will use:

registry.redhat.io/rhscl/nginx-116-rhel7

βœ… It’s an NGINX S2I builder (for serving static websites).


🧰 Step 2: Prepare Source Code (GitHub)

You need a GitHub repo with static website files (HTML/CSS).

Example ready-to-use repo:
➑️ https://github.com/sclorg/nginx-container/tree/master/1.16/test/test-app/

Or you can create your own repo like this:

  1. Create a new GitHub repo:
    Example: https://github.com/yourusername/my-s2i-nginx-app
  2. Add some simple index.html:
<!-- index.html -->
<html>
  <head><title>Welcome to S2I NGINX App</title></head>
  <body><h1>Hello from OpenShift + S2I!</h1></body>
</html>

βœ… Push this file to GitHub.


πŸš€ Step 3: Create S2I App in OpenShift

πŸ‘‰ Login to your OpenShift cluster:

oc login https://your-openshift-cluster:6443

πŸ‘‰ Now create your S2I app:

oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-s2i-nginx-app --strategy=source

βœ… What this command does:

  • Pulls base image nginx-116-rhel7
  • Pulls your source code from GitHub
  • Builds a new image combining both
  • Deploys a pod automatically

🌍 Step 4: Expose Route (to Access App)

Create a Route:

oc expose svc/my-s2i-nginx-app

βœ… Then get the URL:

oc get routes

You’ll get something like:

http://my-s2i-nginx-app-yourproject.apps.cluster.example.com

Open it in browser β€”
✨ You will see your HTML page served from the new OpenShift app!


πŸ“‹ Full Commands Summary

# Login
oc login https://your-openshift-cluster:6443

# Create S2I app
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-s2i-nginx-app --strategy=source

# (Optional) Watch build
oc logs -f bc/my-s2i-nginx-app

# Expose a Route
oc expose svc/my-s2i-nginx-app

# Get public URL
oc get routes

πŸ”₯ Important Tips

ProblemSolution
error: cannot find source repositoryCheck GitHub URL is public
imagepullbackoffCheck cluster can pull Red Hat registry images (pull secret)
App not updating?Run oc start-build my-s2i-nginx-app --from-dir=. to rebuild manually

🧠 Visual Flow

GitHub Repo (HTML)
        ↓
oc new-app (S2I build)
        ↓
BuildConfig + ImageStream created
        ↓
Pod created from new image
        ↓
Service + Route exposed
        ↓
Your app live on internet! πŸš€

πŸ† Final Quick Recap

StepAction
1Pick S2I builder (registry.redhat.io/rhscl/nginx-116-rhel7)
2Prepare GitHub repo (index.html)
3Run oc new-app with --strategy=source
4Expose service using Route

βœ… You now know how to run S2I base images in OpenShift!
βœ… This knowledge is essential for DevOps, OpenShift developers, CI/CD engineers.



Let’s do a real complete project:
You’ll build your own HTML website,
then deploy it into OpenShift using S2I process.


🎯 Project Goal

StepAction
1Create a simple HTML website
2Push the website to GitHub
3Deploy it into OpenShift using S2I base image
4Access your site via OpenShift Route

πŸ›  Step 1: Create Your Own HTML Website

On your local machine, create a project:

mkdir my-openshift-website
cd my-openshift-website

Now create a simple index.html:

<!-- my-openshift-website/index.html -->
<html>
<head>
    <title>Welcome to My OpenShift Website</title>
</head>
<body>
    <h1>Hello World from Rajesh! πŸš€</h1>
    <p>Running on OpenShift with S2I magic!</p>
</body>
</html>

βœ… Done β€” your website is ready.


🌍 Step 2: Push Your Website to GitHub

Initialize Git and push:

git init
git add .
git commit -m "Initial commit - my openshift html site"
git branch -M main
git remote add origin https://github.com/yourusername/my-openshift-website.git
git push -u origin main

βœ… Now your project is live at:

https://github.com/yourusername/my-openshift-website

(Public GitHub repo needed for OpenShift to pull.)


πŸš€ Step 3: Deploy to OpenShift Using S2I

βœ… Login to your OpenShift cluster:

oc login https://your-openshift-cluster:6443

βœ… Now run S2I Deployment:

oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-openshift-website --strategy=source

βœ… OpenShift will:

  • Pull NGINX S2I base image (rhscl/nginx-116-rhel7)
  • Pull your HTML website from GitHub
  • Build a new container image
  • Deploy a Pod automatically

βœ… Watch the build logs (optional):

oc logs -f bc/my-openshift-website

🌐 Step 4: Expose your app with a Route

βœ… Create a Route:

oc expose svc/my-openshift-website

βœ… Get the public URL:

oc get routes

You’ll get something like:

http://my-openshift-website-myproject.apps.cluster.example.com

βœ… Open this URL in browser!

πŸŽ‰ You’ll see:

Hello World from Rajesh! πŸš€
Running on OpenShift with S2I magic!

βœ… Your custom HTML website is now live on OpenShift! 🌟


πŸ“‹ Full Commands Summary (Cheat Sheet)

# 1. Create HTML site
mkdir my-openshift-website && cd my-openshift-website
# (create index.html)

# 2. Push to GitHub
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/yourusername/my-openshift-website.git
git push -u origin main

# 3. Deploy to OpenShift
oc login https://your-openshift-cluster:6443
oc new-app registry.redhat.io/rhscl/nginx-116-rhel7~https://github.com/yourusername/my-openshift-website --strategy=source

# 4. Watch build (optional)
oc logs -f bc/my-openshift-website

# 5. Expose
oc expose svc/my-openshift-website

# 6. Get URL
oc get routes

🧠 Visual Architecture

Your GitHub Repo (index.html)
         ↓
S2I Build Process (oc new-app)
         ↓
BuildConfig + ImageStream
         ↓
New Container Image Created
         ↓
Pod Running + Service
         ↓
Route Created
         ↓
Public Website LIVE πŸš€

πŸ“’ Key Points to Remember

TopicTip
Base Imageregistry.redhat.io/rhscl/nginx-116-rhel7
Strategy--strategy=source
Code LocationPublic GitHub repo
Exposing serviceUse oc expose svc/<service-name>
Cluster pull secretsMust be able to pull Red Hat registry images

πŸ† Now you know how to:

βœ… Create your own HTML app
βœ… Deploy it into OpenShift using S2I
βœ… Access it publicly over internet
βœ… Automate build from GitHub source
βœ… Master basic OpenShift developer workflow πŸš€


Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x