Tutorial: deploy a small web app on OpenShift and expose it with a Route
A step-by-step first deployment: create a project, build a static website from Git with Source-to-Image, publish it on an HTTPS Route, then scale, update and clean up.
Not checked by a trusted editor yet Last edited Outdated?
In this tutorial you deploy a small static website to an OpenShift or OKD cluster using only the oc client. The cluster builds the image for you from a public Git repository, runs it, and publishes it on an HTTPS address. You need an account on a cluster and permission to create a project.
The example uses the Apache httpd builder image from Red Hat’s public registry and the sample repository sclorg/httpd-ex, which contains an index.html. Both work with OpenShift’s default security settings: the server listens on port 8080 and runs as a random, non-root user.
1. Log in and create a project
oc login https://api.cluster.example.com:6443 -u developer
oc new-project hello-web
2. Build and deploy from Git
oc new-app with the builder~repository syntax creates a BuildConfig, image streams, a Deployment and a Service in one go. The build clones the repository, copies the files into the builder image and pushes the result to the internal registry.
oc new-app registry.access.redhat.com/ubi9/httpd-24~https://github.com/sclorg/httpd-ex.git --name=hello
3. Watch the build and the rollout
oc logs -f bc/hello
oc get pods -w
Press Ctrl+C to stop watching. You should see a build pod that ends in Completed and an application pod in Running with 1/1 ready. If the build fails, the log usually says why; if the pod restarts, check oc logs deploy/hello and oc get events --sort-by=.lastTimestamp.
4. Look at what was created
oc status
oc get deployment,svc,is,bc
The service is internal only. It has a stable cluster IP and DNS name inside the cluster but cannot be reached from your browser yet.
5. Publish it with an HTTPS Route
An edge route terminates TLS at the cluster’s router and forwards plain HTTP to your pod. Without your own certificate, the router uses its default certificate for the cluster’s application domain. Setting the insecure policy to Redirect sends visitors who type http:// to the HTTPS address.
oc create route edge hello --service=hello --port=8080 --insecure-policy=Redirect
oc get route hello
The HOST/PORT column shows the generated host name under the cluster’s application domain. Open https:// plus that host name in a browser, or test from the terminal:
HOST=$(oc get route hello -o jsonpath='{.spec.host}')
curl -sI "https://$HOST"
If the page does not load, check that the route points at the right service and port (oc describe route hello) and that the pod is ready. An HTTP 503 page from the router usually means no ready pod is behind the service.
6. Scale and add a health check
oc scale deployment/hello --replicas=2
oc set probe deployment/hello --readiness --get-url=http://:8080/
oc rollout status deployment/hello
With a readiness probe, the router only sends traffic to pods that answer on port 8080, so rollouts do not serve errors while a new pod is starting.
7. Change the app and rebuild
Fork the sample repository, edit index.html, point the build at your fork and start a new build. When the build pushes a new image to the image stream, the deployment rolls out the new version.
oc patch bc/hello --type=merge -p '{"spec":{"source":{"git":{"uri":"https://github.com/YOUR-USER/httpd-ex.git"}}}}'
oc start-build hello --follow
oc rollout status deployment/hello
8. Clean up
Warning: this deletes the whole project and everything in it. Run oc project first to confirm you are about to delete hello-web on the cluster you expect.
oc project
oc delete project hello-web
What you learned
oc new-appcan build from Git with S2I and deploy in a single command.- Services are internal; a Route publishes a service on a host name with TLS handled by the router.
- Builds, image streams and deployments are linked, so a new build leads to a new rollout.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0150 Logging in with oc and working with OpenShift projects Install the oc client, log in with a password, browser or token, then create, switch and inspect projects. Covers where oc stores… Beginner · Step by step · Any system Article Concepts · Deploying applications 15 Oct 2026
- 0152 Build and deploy from source with oc new-app and Source-to-Image How oc new-app turns a Git repository or an image into a running app, how Source-to-Image and Docker builds are chosen, and… Intermediate · Step by step · Any system Article Deploying applications 15 Oct 2026
- 0153 Expose apps with OpenShift Routes: edge, passthrough and re-encrypt TLS A Route publishes a service on a host name through the OpenShift router. Learn when to use plain HTTP, edge, passthrough or… Intermediate · Step by step · Any system Article Deploying applications · Ingress & networking 15 Oct 2026
- 0154 OpenShift app configuration: environment, ConfigMaps, Secrets and persistent storage Set environment variables, load ConfigMaps and Secrets into a Deployment as variables or files, and give it persistent storage with a PersistentVolumeClaim,… Intermediate · Step by step · Any system Article Config, secrets & storage · Deploying applications 15 Oct 2026
- 0157 oc cheat sheet: everyday OpenShift CLI commands The oc commands you use every day, grouped by task: login and projects, apps and builds, routes, config, debugging, permissions and admin… Intermediate · Cheat sheet · Any system Article Deploying applications · Troubleshooting 15 Oct 2026
- 0158 Collect an OpenShift project report with oc A read-only bash script that gathers a project's workloads, pods, routes, builds, storage and warning events, plus describe output and logs of… Intermediate · Step by step · Linux, macOS Script Deploying applications · Troubleshooting 15 Oct 2026
Repos in the wild
- openshift/oc: the OpenShift command line client openshift/oc Source code of oc, the OpenShift CLI. It is built on top of kubectl, so it can do everything kubectl does, and adds commands for projects, builds, routes, image streams and cluster administration. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Commitpedia +3,977 chars