Streamlit deployment with Docker - local works but K8s `You need to enable JavaScript`

Hello,

I developed a Streamlit app and dockerized it. It works smoothly when running locally with Docker. (I followed Deploy Streamlit using Docker - Streamlit Docs)

But when I deploy the container to Kubernetes I cannot see the Streamlit application. In the developer tools of my browser under body I see the following text:

<noscript>You need to enable JavaScript to run this app.</noscript>

The Dockerfile:

FROM python:3.10-slim-bookworm

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY . .
WORKDIR /app/streamlit

RUN pip3 install --upgrade pip3 --no-cache-dir;\
    pip3 install poetry --no-cache-dir;\
    poetry config virtualenvs.create false;\
    poetry install --no-interaction --no-ansi

EXPOSE 8501

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

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

My K8s deployment and service:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - name: frontend
        image: mh-harbor.org/project/frontend:latest
        imagePullPolicy: Always
        env:
          - name: API_BACKEND_URL
            value: http://backend:80
        ports:
          - containerPort: 8501
        livenessProbe:
          httpGet:
            path: /_stcore/health
            port: 8501
            scheme: HTTP
          timeoutSeconds: 1
        readinessProbe:
          httpGet:
            path: /_stcore/health
            port: 8501
            scheme: HTTP
          timeoutSeconds: 1
        resources:
          limits:
            cpu: 1
            memory: 2Gi
          requests:
            cpu: 100m
            memory: 745Mi
---
apiVersion: v1
kind: Service
metadata:
  name: frontend
spec:
  selector:
    app: frontend
  ports:
    - name: "http"
      protocol: TCP
      port: 8501
      targetPort: 8501

and my ingress yaml:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  tls:
  - hosts:
    - app.org
    secretName: app-secret
  ingressClassName: nginx
  rules:
  - host: appss.org
    http:
      paths:
      - path: "/(.*)"
        pathType: Prefix
        backend:
          service:
            name: frontend
            port:
              number: 8501
      - path: "/api(/|$)(.*)"
        pathType: Prefix
        backend:
          service:
            name: backend
            port:
              number: 80

Where is my problem located? Ingress? Service/Deployment? Dockerfile? Kubernetes settings (e.g. ressources)?

Any help very much appreciated!

Same problem with my app deployed on render.com

Has this problem been solved? I have the same issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.