Deploy a streamlit application through openshift

You need to setup your streamlit application.

In an empty folder, create an example application in a file named (for example) example.py:

import streamlit as st

def main():
    st.title("My first streamlit application")
    myname = st.text_input("Name", value="My Name")
    st.write(f"Welcome to my app, {myname}.")

if __name__ == "__main__":
    main()

Create a requirements.txt containing all your dependencies (here only streamlit:

streamlit

Add a DockerFile that will contain how to install your dependencies and run your app:

FROM registry.access.redhat.com/ubi9/python-311:latest

COPY requirements.txt ./requirements.txt
RUN pip3 --no-cache-dir install -r requirements.txt
COPY . .

EXPOSE 8501
ENTRYPOINT ["streamlit", "run", "example.py", "--server.port=8501", "--server.address=0.0.0.0"]

Initialize your git repository (repo.com is your repository server):

cd existing_folder
git init --initial-branch=main
git remote add origin git@repo.com/myapp/myapp.git
git add .
git commit -m "Initial commit"
git push -u origin main

You will then create your project on openshift:

  • Login to openshift oc login --token=mytoken --server=myserver
  • Create your project oc project myproject
  • Create your app in your project oc new-app https://repo.com/myapp/myapp.git
  • Create route to redirect to the app oc create route edge --service myapp
  • Look at oc status