Skip to content

Instantly share code, notes, and snippets.

@RetrieverJo
Created February 1, 2021 08:11
Show Gist options
  • Select an option

  • Save RetrieverJo/1b12f8ab6b2ca337eb048150015f352c to your computer and use it in GitHub Desktop.

Select an option

Save RetrieverJo/1b12f8ab6b2ca337eb048150015f352c to your computer and use it in GitHub Desktop.
Dockerfile, entrypoint.sh and deployment.yaml for model serving client API
#!/bin/bash
export PYTHONPATH=/client_api
export MODEL_BASE_PATH=/resources
python3.7 buzzni/ai/category_api/client/prepare_client.py
python3.7 buzzni/ai/category_api/client/app.py 9090
apiVersion: apps/v1
kind: Deployment
metadata:
name: category-api-client
labels:
app: category-api-client
spec:
replicas: 3
selector:
matchLabels:
app: category-api-client
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: category-api-client
spec:
containers:
- image: asia.gcr.io/storage-273502/buzzni-ai-category-api-client:latest
lifecycle:
preStop:
exec:
command:
- sleep
- "5"
resources:
requests:
cpu: 1
readinessProbe:
httpGet:
path: /
port: 9090
name: category-api-container-client
serviceAccountName: gcs-reader
---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: category-api-client
namespace: default
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: category-api-client
targetCPUUtilizationPercentage: 80
apiVersion: v1
kind: Service
metadata:
labels:
app: category-api-client
name: category-api-client-service
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9090
selector:
app: category-api-client
sessionAffinity: None
type: ClusterIP
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: vpn-web-category-api
namespace: default
spec:
entryPoints:
- vpn-web
routes:
- kind: Rule
match: PathPrefix(`/category-api/`)
middlewares:
- name: api-strip
services:
- name: category-api-client-service
port: 80
FROM python:3.7
# Install apt package
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates software-properties-common git curl
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install poetry
RUN pip3 install poetry
# Prepare tf-serving model
WORKDIR /client_api
COPY poetry.lock .
COPY pyproject.toml .
# Install dependency packages
RUN poetry config virtualenvs.create false
RUN poetry install -n
# Copy other files
COPY . .
# REST
EXPOSE 9090
# Make entrypoint
RUN chmod +x scripts/client_api_entrypoint.sh
ENTRYPOINT ["scripts/client_api_entrypoint.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment