https://github.com/rguske/openshift-serverless-serving
Demoing OpenShift Serverless/Knative Serving power
https://github.com/rguske/openshift-serverless-serving
Last synced: about 2 months ago
JSON representation
Demoing OpenShift Serverless/Knative Serving power
- Host: GitHub
- URL: https://github.com/rguske/openshift-serverless-serving
- Owner: rguske
- Created: 2024-12-15T09:02:12.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-17T14:23:03.000Z (4 months ago)
- Last Synced: 2025-02-13T17:51:45.231Z (3 months ago)
- Language: Python
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Red Hat OpenShift Serverless Serving Demo
This repository is intent to provide information on Red Hat's OpenShift Serverless (Knative Serving) capabilities. I'm using a simple web app which is written in Python.
```python
[...]@app.route("/")
def home():
# Get the message and image path from environment variables or use defaults
message = os.getenv("MESSAGE", "Hello, World!")
image_path = os.getenv("IMAGE_PATH", "static/default.jpg")
image_url = f"/images/{os.path.basename(image_path)}"
print(f"Message: {message}, Image Path: {image_path}") # Print to stdout
return render_template_string(HTML_TEMPLATE, message=message, image_url=image_url)[...]
```In order to demonstrate e.g. traffic splitting functionalities, the displayed text which the web outputs when browsing or `curl`ing it, can be changed by adjusting the environment variables for the container (`--env MESSAGE='Who is it?'`).
## Knative Serving
Knative Serving is the runtime component of the Knative project. At its core, Knative Serving provides a Kubernetes-native platform to deploy, run, and manage modern `HTTP` workloads. In the context of Knative, serverless implies Knative's ability to abstracts away much of the underlying infrastructure complexity, allowing relevant teams to focus on writing code and defining the desired state of their applications.
Key capabilities of Serving are:
- Serverless experience for `HTTP` workloads
- Scale-to-zero, request-driven compute runtime
- Point-in-time snapshot of your code and configuration (`Revision`)
- Traffic routing amongst `revisions`
- Supports deployment patterns like Blue/Green, Canary and Progressive
- Automatic DNS and TLS handling## Build the Demo Application
You can build the application on your own using e.g. [Podman](https://podman.io/). Follow the provided steps:
Clone the Github repository:
`git clone [email protected]:rguske/openshift-serverless-demo.git`
Navigate into the folder (`cd demo-app`) and start buidling the app from scratch.
`podman build -t simple-serverless-app:1.0 -f demo-app/Containerfile`
Check the build:
```code
podman imagesREPOSITORY TAG IMAGE ID CREATED SIZE
localhost/simple-web-app 1.0 8769fca45f40 About a minute ago 168 MB
docker.io/library/python 3.9-slim 95eddd44d6c4 6 days ago 155 MB
```Run the app locally to see if it works or to apply your changes.
`podman run -d -p 8080:8080 -e MESSAGE="Who is it?" localhost/simple-serverless-app:1.0`
## Run the app as a Kubernetes deployment on OpenShift
Adjust the variables for your namespace and for the text accordingly:
```bash
export NS=rguske-kn-serving
export MESSAGE='HI THERE'
```Now, by copy and pasting the following, a Pod, a Service (`type: ClusterIP`) and a Route will be created.
```yaml
oc create -n ${NS} -f - <-.example.com`. You can customize the domain for your Knative service by mapping a custom domain name that you own to a Knative service.You can do this by creating a DomainMapping resource for the service. You can also create multiple DomainMapping resources to map multiple domains and subdomains to a single service.