Skip to content

Commit

Permalink
L9T3: K8S deployments of streamlit and fastapi (#16)
Browse files Browse the repository at this point in the history
* change docker file config to add new images

* fastapi and streamlit deployment

* update readme with deployments

* fix name of builder image

* add servings to ci
  • Loading branch information
yuriihavrylko authored Feb 11, 2024
1 parent eb4e0f7 commit 0eca8ff
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Deploy Image to Docker Hub

env:
APP_NAME: 'prjctr'
STREAMLIT_NAME: 'app-streamlit'
FASTAPI_NAME: 'app-fastapi'

on:
push:
Expand Down Expand Up @@ -52,3 +54,12 @@ jobs:
run: |
docker build . --tag docker.io/${{ secrets.DH_USERNAME }}/$APP_NAME:latest
docker push docker.io/${{ secrets.DH_USERNAME }}/$APP_NAME:latest
- name: 'Build & Push Image streamlit'
run: |
docker build . --tag docker.io/${{ secrets.DH_USERNAME }}/$STREAMLIT_NAME:latest
docker push docker.io/${{ secrets.DH_USERNAME }}/$STREAMLIT_NAME:latest
- name: 'Build & Push Image fastapi'
run: |
docker build . --tag docker.io/${{ secrets.DH_USERNAME }}/$FASTAPI_NAME:latest
docker push docker.io/${{ secrets.DH_USERNAME }}/$FASTAPI_NAME:latest
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ WORKDIR /app
COPY app/requirements.txt .
RUN pip install -r requirements.txt

FROM builder
FROM builder AS app-flask

COPY app .
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]
EXPOSE 8000

FROM builder AS app-streamlit
CMD streamlit run --server.address 0.0.0.0 --server.port 8080 src/serving/streamlit.py


FROM builder AS app-fastapi
CMD uvicorn --host 0.0.0.0 --port 8090 --workers 4 src.serving.fastapi:app
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ streamlit run src/serving/streamlit.py

![Alt text](assets/streamlit.png)

Deploy k8s:
```
kubectl create -f deployment/app-ui.yml
kubectl port-forward --address 0.0.0.0 svc/app-ui.yml 8080:8080
```

### Fast API

Postman

![Alt text](assets/fastapi.png)


Deploy k8s:
```
kubectl create -f deployment/app-fasttext.yml
kubectl port-forward --address 0.0.0.0 svc/app-fasttext 8090:8090
```
31 changes: 31 additions & 0 deletions deployment/app-fastapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-fastapi
spec:
replicas: 2
selector:
matchLabels:
app: app-fastapi
template:
metadata:
labels:
app: app-fastapi
spec:
containers:
- name: app-fastapi
image: yuriihavrylko/app-fastapi:latest
---
apiVersion: v1
kind: Service
metadata:
name: app-fastapi
labels:
app: app-fastapi
spec:
ports:
- port: 8080
protocol: TCP
selector:
app: app-fastapi
31 changes: 31 additions & 0 deletions deployment/app-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-fastapi
spec:
replicas: 2
selector:
matchLabels:
app: app-fastapi
template:
metadata:
labels:
app: app-fastapi
spec:
containers:
- name: app-fastapi
image: yuriihavrylko/app-streamlit:latest
---
apiVersion: v1
kind: Service
metadata:
name: app-fastapi
labels:
app: app-fastapi
spec:
ports:
- port: 8080
protocol: TCP
selector:
app: app-fastapi

0 comments on commit 0eca8ff

Please sign in to comment.