Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docker/services/netease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ services:
- CAT_BACKEND_PORT=8888
- CAT_BACKEND_HOST=netease
- CAT_BACKEND_ALLOWED_ORIGINS=["*"]
healthcheck:
test: ["CMD-SHELL", "curl --fail http://$$CAT_BACKEND_HOST:$$CAT_BACKEND_PORT/api/healthz || exit 1"]
interval: 2s
timeout: 5s
retries: 3
start_period: 5s
networks:
- netease_network
6 changes: 6 additions & 0 deletions docker/services/streamlit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ services:
- "8501:8501"
environment:
- UI_BACKEND_URL=http://netease:8888
healthcheck:
test: ["CMD-SHELL", "curl --fail http://streamlit:8501/api/healthz || exit 1"]
interval: 2s
timeout: 5s
retries: 3
start_period: 5s
networks:
- netease_network
16 changes: 16 additions & 0 deletions k8s/configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-config
data:
UI_BACKEND_URL: "http://backend:8888"

---
apiVersion: v1
kind: ConfigMap
metadata:
name: backend-config
data:
CAT_BACKEND_PORT: "8888"
CAT_BACKEND_HOST: "backend"
CAT_BACKEND_ALLOWED_ORIGINS: '["*"]'
105 changes: 105 additions & 0 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
app.kubernetes.io/name: frontend
spec:
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: alaricle/streamlit:latest
ports:
- containerPort: 8501
name: pod-http
resources:
requests:
memory: "64Mi"
cpu: "64m"
limits:
memory: "200Mi"
cpu: "128m"
envFrom:
- configMapRef:
name: frontend-config
livenessProbe:
httpGet:
path: /liveness
port: myport
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 1
startupProbe:
httpGet:
path: /healthz
port: myport
failureThreshold: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: myport
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 1
successThreshold: 3
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
labels:
app.kubernetes.io/name: backend
spec:
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: alaricle/netease:latest
ports:
- containerPort: 8888
name: pod-http
resources:
requests:
memory: "64Mi"
cpu: "64m"
limits:
memory: "200Mi"
cpu: "128m"
envFrom:
- configMapRef:
name: backend-config
livenessProbe:
httpGet:
path: /liveness
port: myport
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 1
startupProbe:
httpGet:
path: /healthz
port: myport
failureThreshold: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: myport
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 1
successThreshold: 3
37 changes: 37 additions & 0 deletions k8s/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: netease-fe-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: frontend
minReplicas: 1
maxReplicas: 6
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: netease-be-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: backend
minReplicas: 1
maxReplicas: 6
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
30 changes: 30 additions & 0 deletions k8s/ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: todo
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/issuer: "letsencrypt-prod"
spec:
tls:
- hosts:
- 441781.learnk8s.jamesisme.com
secretName: todo-tls
rules:
- host: 441781.learnk8s.jamesisme.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
name: svc-http
# - path: /api
# pathType: Prefix
# backend:
# service:
# name: backend
# port:
# name: svc-http
18 changes: 18 additions & 0 deletions k8s/issuer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: letsencrypt-prod
spec:
acme:
# The ACME server URL
server: https://acme-v02.api.letsencrypt.org/directory
# Email address used for ACME registration
email: ghbihuy123@gmail.com
# Name of a secret used to store the ACME account private key
privateKeySecretRef:
name: letsencrypt-prod
# Enable the HTTP-01 challenge provider
solvers:
- http01:
ingress:
class: nginx
32 changes: 32 additions & 0 deletions k8s/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: frontend
spec:
type: ClusterIP
ports:
- port: 80
name: svc-http
targetPort: pod-http
protocol: TCP
selector:
app: frontend

---
apiVersion: v1
kind: Service
metadata:
name: backend
labels:
app: backend
spec:
type: ClusterIP
ports:
- port: 8888
name: svc-http
targetPort: pod-http
protocol: TCP
selector:
app: backend
4 changes: 4 additions & 0 deletions src/cat/api/routers/net_ease.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ async def upload_excel(
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
headers={"Content-Disposition": "attachment; filename=processed_salaries.xlsx"},
)

@router.get("/healthz")
def health_check():
return {"status": "healthy"}