update kubeflow dip-catalog

This commit is contained in:
ChanghoWoo
2025-01-13 02:31:27 +00:00
parent 1dc1181a03
commit 5451f16d72
1959 changed files with 602337 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
KSERVE_VERSION ?= 0.12.1
MODELS_WEBAPP_VERSION ?= 0.8.1
MODELS_WEBAPP_RELEASE_VERSION := $(shell echo ${MODELS_WEBAPP_VERSION} | cut -d "." -f1-2)
.PHONY: upgrade-kserve-manifests
upgrade-kserve-manifests: clean-kserve-manifests
curl -sSL 'https://github.com/kserve/kserve/releases/download/v$(KSERVE_VERSION)/kserve_kubeflow.yaml' -o 'kserve/kserve_kubeflow.yaml'
curl -sSL 'https://github.com/kserve/kserve/releases/download/v$(KSERVE_VERSION)/kserve-cluster-resources.yaml' -o 'kserve/kserve-cluster-resources.yaml'
curl -sSL 'https://github.com/kserve/kserve/releases/download/v$(KSERVE_VERSION)/kserve.yaml' -o 'kserve/kserve.yaml'
.PHONY: clean-kserve-manifests
clean-kserve-manifests:
cd kserve && rm -f kserve.yaml kserve-cluster-resources.yaml kserve_kubeflow.yaml
.PHONY: install-kserve
install-kserve:
# Create kubeflow namespace if not exists
kubectl create namespace kubeflow || echo "kubeflow namespace exists"
kubectl apply -k kserve
.PHONY: uninstall-kserve
uninstall-kserve:
kubectl delete -k kserve
.PHONY: test-kserve
test-kserve:
cd tests && pytest .
.PHONY: clean-models-webapp-manifests
clean-models-webapp-manifests:
rm -rf models-web-app
.PHONY: upgrade-models-webapp-manifests
upgrade-models-webapp-manifests: clean-models-webapp-manifests
git clone https://github.com/kserve/models-web-app.git kserve-models-web-app-src
cd kserve-models-web-app-src && git checkout release-${MODELS_WEBAPP_RELEASE_VERSION}
cp -r kserve-models-web-app-src/config ./models-web-app
# cleanup
rm -rf kserve-models-web-app-src
.PHONY: install-models-web-app
install-models-webapp:
# Create kubeflow namespace if not exists
kubectl create namespace kubeflow || echo "kubeflow namespace exists"
kubectl apply -k models-web-app/overlays/kubeflow
.PHONY: uninstall-models-web-app
uninstall-models-webapp:
kubectl delete -k models-web-app/overlays/kubeflow
.PHONY: test-models-webapp
test-models-webapp: install-models-webapp
kubectl wait --for=condition=Available --timeout=300s -n kubeflow deployment/kserve-models-web-app
@echo "Test Passed"
@echo "cleaning up ..."
kubectl delete -k models-web-app/overlays/kubeflow
+2
View File
@@ -0,0 +1,2 @@
approvers:
- yuzisun
+120
View File
@@ -0,0 +1,120 @@
# KServe
[![Go Report Card](https://goreportcard.com/badge/github.com/kserve/kserve)](https://goreportcard.com/report/github.com/kserve/kserve)
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/6643/badge)](https://bestpractices.coreinfrastructure.org/projects/6643)
[![Releases](https://img.shields.io/github/release-pre/kserve/kserve.svg?sort=semver)](https://github.com/kserve/kserve/releases)
[![LICENSE](https://img.shields.io/github/license/kserve/kserve.svg)](https://github.com/kserve/kserve/blob/master/LICENSE)
KServe provides a Kubernetes [Custom Resource Definition](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) for serving predictive and generative machine learning (ML) models. It aims to solve production model serving use cases by providing high abstraction interfaces for Tensorflow, XGBoost, ScikitLearn, PyTorch, Huggingface Transformer/LLM models using standardized data plane protocols.
It encapsulates the complexity of autoscaling, networking, health checking, and server configuration to bring cutting edge serving features like GPU Autoscaling, Scale to Zero, and Canary Rollouts to your ML deployments. It enables a simple, pluggable, and complete story for Production ML Serving including prediction, pre-processing, post-processing and explainability. KServe is being [used across various organizations.](https://kserve.github.io/website/master/community/adopters/)
For more details, visit the [KServe website](https://kserve.github.io/website/).
![KServe](assets/kserve_new.png)
*[KFServing has been rebranded to KServe since v0.7](https://blog.kubeflow.org/release/official/2021/09/27/kfserving-transition.html).*
## Why KServe?
- KServe is a standard, cloud agnostic **Model Inference Platform** for serving predictive and generative AI models on Kubernetes, built for highly scalable use cases.
- Provides performant, **standardized inference protocol** across ML frameworks including OpenAI specification for generative models.
- Support modern **serverless inference workload** with **request based autoscaling including scale-to-zero** on **CPU and GPU**.
- Provides **high scalability, density packing and intelligent routing** using **ModelMesh**.
- **Simple and pluggable production serving** for **inference**, **pre/post processing**, **monitoring** and **explainability**.
- Advanced deployments for **canary rollout**, **pipeline**, **ensembles** with **InferenceGraph**.
## :hammer_and_wrench: Installation
### Standalone Installation
- **[Serverless Installation](https://kserve.github.io/website/master/admin/serverless/serverless/)**: KServe by default installs Knative for **serverless deployment** for InferenceService.
- **[Raw Deployment Installation](https://kserve.github.io/website/master/admin/kubernetes_deployment)**: Compared to Serverless Installation, this is a more **lightweight** installation. However, this option does not support canary deployment and request based autoscaling with scale-to-zero.
- **[ModelMesh Installation](https://kserve.github.io/website/master/admin/modelmesh/)**: You can optionally install ModelMesh to enable **high-scale**, **high-density** and **frequently-changing model serving** use cases.
- **[Quick Installation](https://kserve.github.io/website/master/get_started/)**: Install KServe on your local machine.
### Kubeflow Installation
KServe is an important addon component of Kubeflow, please learn more from the [Kubeflow KServe documentation](https://www.kubeflow.org/docs/external-add-ons/kserve/kserve) and follow [KServe with Kubeflow on AWS](https://awslabs.github.io/kubeflow-manifests/main/docs/component-guides/kserve) to learn how to use KServe on AWS.
## :hammer_and_pick: Models Web App
The Models web app is responsible for allowing the user to manipulate the Model Servers in their Kubeflow cluster. To achieve this it provides a user friendly way to handle the lifecycle of InferenceService CRs.
Please follow the [Kserve Models UI documentation](https://www.kubeflow.org/docs/external-add-ons/kserve/webapp/) for more information.
## :rocket: Upgrading
For upgrading see [UPGRADE.md](UPGRADE.md)
## :microscope: Testing
### Testing Kserve
#### Prerequisite
1. Install Python >= 3.8
2. Install requirements
```sh
pip install -r tests/requirements.txt
```
3. Create kubeflow namespace
```sh
kubectl apply -k ../../common/kubeflow-namespace/base
```
4. Install cert manager
```sh
kubectl apply -k ../../common/cert-manager/cert-manager/base
kubectl apply -k ../../common/cert-manager/kubeflow-issuer/base
```
5. Install Istio
```sh
kubectl apply -k ../../common/istio-1-22/istio-crds/base
kubectl apply -k ../../common/istio-1-22/istio-namespace/base
kubectl apply -k ../../common/istio-1-22/istio-install/base
```
6. Install knative
```sh
kubectl apply -k ../../common/knative/knative-serving/overlays/gateways
kubectl apply -k ../../common/istio-1-22/cluster-local-gateway/base
kubectl apply -k ../../common/istio-1-22/kubeflow-istio-resources/base
```
7. Install kserve
```sh
make install-kserve
```
> **_NOTE:_** If resource/crd installation fails please re-run the commands.
#### Steps
1. Create test namespace
```sh
kubectl create ns kserve-test
```
2. Configure domain name
```sh
kubectl patch cm config-domain --patch '{"data":{"example.com":""}}' -n knative-serving
```
3. Port forward
```sh
# start a new terminal and run
INGRESS_GATEWAY_SERVICE=$(kubectl get svc --namespace istio-system --selector="app=istio-ingressgateway" --output jsonpath='{.items[0].metadata.name}')
kubectl port-forward --namespace istio-system svc/${INGRESS_GATEWAY_SERVICE} 8080:80
```
4. Run test
```sh
export KSERVE_INGRESS_HOST_PORT='localhost:8080'
make test-kserve
### Testing Models WebApp
#### Prerequisite
1. Running kubernetes cluster
2. `kubectl` configured to talk to the desired cluster.
#### Steps
1. Run the test
```sh
make test-models-webapp
```
## :flight_departure: [Create your first InferenceService](https://kserve.github.io/website/master/get_started/first_isvc)
## :blue_book: [InferenceService API Reference](https://kserve.github.io/website/master/reference/api/)
## :handshake: [Adopters](https://kserve.github.io/website/master/community/adopters/)
## :books: Learn More
To learn more about KServe, how to use various supported features, and how to participate in the KServe community,
please follow the [KServe website documentation](https://kserve.github.io/website).
Additionally, we have compiled a list of [presentations and demos](https://kserve.github.io/website/master/community/presentations/) to dive through various details.
+68
View File
@@ -0,0 +1,68 @@
# Upgrade Documentation
## Upgrade Kserve
### Prerequisites
- Running Kubernetes cluster with kubeflow installed.
- `kubectl` configured to talk to the desired cluster.
- `curl`
> **_NOTE:_** This documentation assumes that you are running the commands in linux.
If you are using another OS, please make sure to update the Makefile commands.
### To update the kserve manifests to specific version follow the below instructions.
1. Set the desired version to upgrade.
```sh
export KSERVE_VERSION=0.12.1
```
2. Rebuild the manifests.
```sh
make upgrade-kserve-manifests
```
3. Install the updated manifests.
```sh
make install-kserve
```
> **_NOTE:_** If resource/crd installation fails please re-run the commands.
### Testing
For testing refer [kserve readme](README.md#testing-kserve).
## Upgrade Models Webapp
### Prerequisites
- Running Kubernetes cluster with kubeflow installed.
- `kubectl` configured to talk to the desired cluster.
- `git`
> **_NOTE:_** This documentation assumes that you are running the commands in linux.
If you are using another OS, please make sure to update the Makefile commands.
### To update the kserve manifests to specific version follow the below instructions.
1. Set the desired version to upgrade.
```sh
export MODELS_WEBAPP_VERSION=0.8.1
```
2. Rebuild the manifests.
```sh
make upgrade-models-webapp-manifests
```
3. Install the updated manifests.
```sh
make install-models-webapp
```
> **_NOTE:_** If resource/crd installation fails please re-run the commands.
### Testing
For testing refer [kserve readme](README.md#testing-models-webapp).
Binary file not shown.

After

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

@@ -0,0 +1,89 @@
aggregationRule:
clusterRoleSelectors:
- matchLabels:
rbac.authorization.kubeflow.org/aggregate-to-kubeflow-kserve-admin: "true"
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: kserve
app.kubernetes.io/name: kserve
rbac.authorization.kubeflow.org/aggregate-to-kubeflow-admin: "true"
name: kubeflow-kserve-admin
rules: []
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: kserve
app.kubernetes.io/name: kserve
rbac.authorization.kubeflow.org/aggregate-to-kubeflow-edit: "true"
rbac.authorization.kubeflow.org/aggregate-to-kubeflow-kserve-admin: "true"
name: kubeflow-kserve-edit
rules:
- apiGroups:
- serving.kserve.io
resources:
- inferenceservices
verbs:
- get
- list
- watch
- create
- delete
- deletecollection
- patch
- update
- apiGroups:
- serving.knative.dev
resources:
- services
- services/status
- routes
- routes/status
- configurations
- configurations/status
- revisions
- revisions/status
verbs:
- get
- list
- watch
- create
- delete
- deletecollection
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: kserve
app.kubernetes.io/name: kserve
rbac.authorization.kubeflow.org/aggregate-to-kubeflow-view: "true"
name: kubeflow-kserve-view
rules:
- apiGroups:
- serving.kserve.io
resources:
- inferenceservices
verbs:
- get
- list
- watch
- apiGroups:
- serving.knative.dev
resources:
- services
- services/status
- routes
- routes/status
- configurations
- configurations/status
- revisions
- revisions/status
verbs:
- get
- list
@@ -0,0 +1,391 @@
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-huggingfaceserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
image: kserve/huggingfaceserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v2
- v1
supportedModelFormats:
- autoSelect: true
name: huggingface
priority: 1
version: "1"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-lgbserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --model_dir=/mnt/models
- --http_port=8080
- --nthread=1
image: kserve/lgbserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
supportedModelFormats:
- autoSelect: true
name: lightgbm
priority: 1
version: "3"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-mlserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- env:
- name: MLSERVER_MODEL_IMPLEMENTATION
value: '{{.Labels.modelClass}}'
- name: MLSERVER_HTTP_PORT
value: "8080"
- name: MLSERVER_GRPC_PORT
value: "9000"
- name: MODELS_DIR
value: /mnt/models
image: docker.io/seldonio/mlserver:1.3.2
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v2
supportedModelFormats:
- autoSelect: true
name: sklearn
priority: 2
version: "0"
- autoSelect: true
name: sklearn
priority: 2
version: "1"
- autoSelect: true
name: xgboost
priority: 2
version: "1"
- autoSelect: true
name: lightgbm
priority: 2
version: "3"
- autoSelect: true
name: mlflow
priority: 1
version: "1"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-paddleserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --model_dir=/mnt/models
- --http_port=8080
image: kserve/paddleserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
supportedModelFormats:
- autoSelect: true
name: paddle
priority: 1
version: "2"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-pmmlserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --model_dir=/mnt/models
- --http_port=8080
image: kserve/pmmlserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
supportedModelFormats:
- autoSelect: true
name: pmml
priority: 1
version: "3"
- autoSelect: true
name: pmml
priority: 1
version: "4"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-sklearnserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --model_dir=/mnt/models
- --http_port=8080
image: kserve/sklearnserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
supportedModelFormats:
- autoSelect: true
name: sklearn
priority: 1
version: "1"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-tensorflow-serving
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --port=9000
- --rest_api_port=8080
- --model_base_path=/mnt/models
- --rest_api_timeout_in_ms=60000
command:
- /usr/bin/tensorflow_model_server
image: tensorflow/serving:2.6.2
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- grpc-v1
supportedModelFormats:
- autoSelect: true
name: tensorflow
priority: 2
version: "1"
- autoSelect: true
name: tensorflow
priority: 2
version: "2"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-torchserve
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8082"
containers:
- args:
- torchserve
- --start
- --model-store=/mnt/models/model-store
- --ts-config=/mnt/models/config/config.properties
env:
- name: TS_SERVICE_ENVELOPE
value: '{{.Labels.serviceEnvelope}}'
image: pytorch/torchserve-kfs:0.9.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
- grpc-v2
supportedModelFormats:
- autoSelect: true
name: pytorch
priority: 2
version: "1"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-tritonserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8002"
containers:
- args:
- tritonserver
- --model-store=/mnt/models
- --grpc-port=9000
- --http-port=8080
- --allow-grpc=true
- --allow-http=true
image: nvcr.io/nvidia/tritonserver:23.05-py3
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v2
- grpc-v2
supportedModelFormats:
- autoSelect: true
name: tensorrt
priority: 1
version: "8"
- autoSelect: true
name: tensorflow
priority: 1
version: "1"
- autoSelect: true
name: tensorflow
priority: 1
version: "2"
- autoSelect: true
name: onnx
priority: 1
version: "1"
- name: pytorch
version: "1"
- autoSelect: true
name: triton
priority: 1
version: "2"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterServingRuntime
metadata:
name: kserve-xgbserver
spec:
annotations:
prometheus.kserve.io/path: /metrics
prometheus.kserve.io/port: "8080"
containers:
- args:
- --model_name={{.Name}}
- --model_dir=/mnt/models
- --http_port=8080
- --nthread=1
image: kserve/xgbserver:v0.13.0
name: kserve-container
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
protocolVersions:
- v1
- v2
supportedModelFormats:
- autoSelect: true
name: xgboost
priority: 1
version: "1"
---
apiVersion: serving.kserve.io/v1alpha1
kind: ClusterStorageContainer
metadata:
name: default
spec:
container:
image: kserve/storage-initializer:v0.13.0
name: storage-initializer
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 100m
memory: 100Mi
supportedUriFormats:
- prefix: gs://
- prefix: s3://
- prefix: hdfs://
- prefix: webhdfs://
- regex: https://(.+?).blob.core.windows.net/(.+)
- regex: https://(.+?).file.core.windows.net/(.+)
- regex: https?://(.+)/(.+)
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
# Install Kserve in kubeflow namespace
- kserve_kubeflow.yaml
- kserve-cluster-resources.yaml
@@ -0,0 +1 @@
ingressGateway=kubeflow/kubeflow-gateway
@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kserve-models-web-app
namespace: kserve
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/component: kserve-models-web-app
template:
metadata:
labels:
app.kubernetes.io/component: kserve-models-web-app
spec:
containers:
- image: kserve/models-web-app:latest
imagePullPolicy: Always
name: kserve-models-web-app
envFrom:
- configMapRef:
name: kserve-models-web-app-config
ports:
- containerPort: 5000
name: http
livenessProbe:
httpGet:
path: /healthz/liveness
port: http
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
readinessProbe:
httpGet:
path: /healthz/readiness
port: http
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
successThreshold: 1
serviceAccountName: kserve-models-web-app
@@ -0,0 +1,21 @@
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: kserve-models-web-app
namespace: kserve
spec:
gateways:
- knative-serving/knative-ingress-gateway
hosts:
- '*'
http:
- match:
- uri:
prefix: /kserve-endpoints/
rewrite:
uri: /
route:
- destination:
host: kserve-models-web-app.kserve.svc.cluster.local
port:
number: 80
@@ -0,0 +1,20 @@
resources:
- rbac.yaml
- service.yaml
- deployment.yaml
- istio.yaml
namespace: kserve
commonLabels:
kustomize.component: kserve-models-web-app
app.kubernetes.io/component: kserve-models-web-app
images:
- name: kserve/models-web-app
newName: kserve/models-web-app
newTag: v0.13.0-rc.0
configMapGenerator:
- name: kserve-models-web-app-config
literals:
- APP_DISABLE_AUTH="True"
@@ -0,0 +1,68 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: kserve-models-web-app
namespace: kserve
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kserve-models-web-app-cluster-role
rules:
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- ""
resources:
- namespaces
- pods
- pods/log
- events
verbs:
- get
- list
- apiGroups:
- serving.kserve.io
resources:
- inferenceservices
- inferenceservices/status
verbs:
- get
- list
- watch
- create
- delete
- deletecollection
- patch
- update
- apiGroups:
- serving.knative.dev
resources:
- services
- services/status
- routes
- routes/status
- configurations
- configurations/status
- revisions
- revisions/status
verbs:
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kserve-models-web-app-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kserve-models-web-app-cluster-role
subjects:
- kind: ServiceAccount
name: kserve-models-web-app
namespace: kserve
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: kserve-models-web-app
namespace: kserve
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 5000
selector:
app.kubernetes.io/component: kserve-models-web-app
type: ClusterIP
@@ -0,0 +1,42 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
# Adds namespace to all resources.
namespace: kubeflow
# Labels to add to all resources and selectors.
commonLabels:
app: kserve
app.kubernetes.io/name: kserve
bases:
- ../../base
- web-app-authorization-policy.yaml
patchesStrategicMerge:
- patches/web-app-sidecar.yaml
patchesJson6902:
- target:
group: networking.istio.io
version: v1beta1
kind: VirtualService
name: kserve-models-web-app
namespace: kserve
path: patches/web-app-vsvc.yaml
generatorOptions:
disableNameSuffixHash: true
# To make namespace for standalone installation kustomizable,
# variabalize ingress gateway, webhook service name and
# kserve namespace in webhook configurations
configMapGenerator:
- name: kserve-models-web-app-config
behavior: replace
literals:
- USERID_HEADER=kubeflow-userid
- APP_PREFIX=/kserve-endpoints
configurations:
- params.yaml
@@ -0,0 +1,4 @@
commonLabels:
- kind: AuthorizationPolicy
path: spec/selector/matchLabels
create: true
@@ -0,0 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kserve-models-web-app
namespace: kserve
spec:
template:
metadata:
annotations:
sidecar.istio.io/inject: "true"
@@ -0,0 +1,14 @@
- op: replace
path: /spec/gateways
value:
- kubeflow/kubeflow-gateway
- op: replace
path: /spec/http/0/route/0/destination
value:
host: kserve-models-web-app.kubeflow.svc.cluster.local
port:
number: 80
- op: replace
path: /spec/gateways
value:
- kubeflow/kubeflow-gateway
@@ -0,0 +1,18 @@
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
labels:
kustomize.component: kserve-models-web-app
app.kubernetes.io/component: kserve-models-web-app
name: kserve-models-web-app
spec:
action: ALLOW
selector:
matchLabels:
kustomize.component: kserve-models-web-app
app.kubernetes.io/component: kserve-models-web-app
rules:
- from:
- source:
principals:
- cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account
@@ -0,0 +1,6 @@
{
"instances": [
[6.8, 2.8, 4.8, 1.4],
[6.0, 3.4, 4.5, 1.6]
]
}
@@ -0,0 +1,4 @@
pytest>=7.0.0
kserve>=0.12.1
kubernetes>=18.20.0
requests>=2.18.4
@@ -0,0 +1,60 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from kubernetes import client
from kubernetes.client import V1ResourceRequirements
from kserve import (
constants,
KServeClient,
V1beta1InferenceService,
V1beta1InferenceServiceSpec,
V1beta1PredictorSpec,
V1beta1SKLearnSpec,
)
from utils import KSERVE_TEST_NAMESPACE
from utils import predict
def test_sklearn_kserve():
service_name = "isvc-sklearn"
predictor = V1beta1PredictorSpec(
min_replicas=1,
sklearn=V1beta1SKLearnSpec(
storage_uri="gs://kfserving-examples/models/sklearn/1.0/model",
resources=V1ResourceRequirements(
requests={"cpu": "50m", "memory": "128Mi"},
limits={"cpu": "100m", "memory": "256Mi"},
),
),
)
isvc = V1beta1InferenceService(
api_version=constants.KSERVE_V1BETA1,
kind=constants.KSERVE_KIND,
metadata=client.V1ObjectMeta(
name=service_name, namespace=KSERVE_TEST_NAMESPACE
),
spec=V1beta1InferenceServiceSpec(predictor=predictor),
)
kserve_client = KServeClient(
config_file=os.environ.get("KUBECONFIG", "~/.kube/config")
)
kserve_client.create(isvc)
kserve_client.wait_isvc_ready(service_name, namespace=KSERVE_TEST_NAMESPACE)
res = predict(service_name, "./data/iris_input.json")
assert res["predictions"] == [1, 1]
kserve_client.delete(service_name, KSERVE_TEST_NAMESPACE)
@@ -0,0 +1,125 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import logging
import os
import time
from urllib.parse import urlparse
import requests
from kubernetes import client
from kserve import KServeClient
from kserve import constants
logging.basicConfig(level=logging.INFO)
KSERVE_NAMESPACE = "kserve"
KSERVE_TEST_NAMESPACE = "kserve-test"
MODEL_CLASS_NAME = "modelClass"
class M2mTokenNotAvailable(Exception):
pass
def get_cluster_ip(name="istio-ingressgateway", namespace="istio-system"):
api_instance = client.CoreV1Api(client.ApiClient())
service = api_instance.read_namespaced_service(name, namespace)
if service.status.load_balancer.ingress is None:
cluster_ip = service.spec.cluster_ip
else:
if service.status.load_balancer.ingress[0].hostname:
cluster_ip = service.status.load_balancer.ingress[0].hostname
else:
cluster_ip = service.status.load_balancer.ingress[0].ip
return os.environ.get("KSERVE_INGRESS_HOST_PORT", cluster_ip)
def get_m2m_auth_token(env_name="KSERVE_M2M_TOKEN"):
try:
return os.environ[env_name]
except KeyError:
raise M2mTokenNotAvailable(env_name)
def predict(
service_name,
input_json,
protocol_version="v1",
version=constants.KSERVE_V1BETA1_VERSION,
model_name=None,
):
with open(input_json) as json_file:
data = json.load(json_file)
return predict_str(
service_name=service_name,
input_json=json.dumps(data),
protocol_version=protocol_version,
version=version,
model_name=model_name,
)
def predict_str(
service_name,
input_json,
protocol_version="v1",
version=constants.KSERVE_V1BETA1_VERSION,
model_name=None,
):
kfs_client = KServeClient(
config_file=os.environ.get("KUBECONFIG", "~/.kube/config")
)
isvc = kfs_client.get(
service_name,
namespace=KSERVE_TEST_NAMESPACE,
version=version,
)
# temporary sleep until this is fixed https://github.com/kserve/kserve/issues/604
time.sleep(10)
cluster_ip = get_cluster_ip()
host = urlparse(isvc["status"]["url"]).netloc
headers = {
"Host": host,
"Content-Type": "application/json",
}
try:
token = get_m2m_auth_token()
headers.update({"Authorization": f"Bearer {token}"})
logging.info("M2M Token Found.")
except M2mTokenNotAvailable:
logging.warn("M2M Token Not found, client authentication disabled.")
if model_name is None:
model_name = service_name
url = f"http://{cluster_ip}/v1/models/{model_name}:predict"
if protocol_version == "v2":
url = f"http://{cluster_ip}/v2/models/{model_name}/infer"
logging.info("Sending Header = %s", headers)
logging.info("Sending url = %s", url)
logging.info("Sending request data: %s", input_json)
response = requests.post(url, input_json, headers=headers)
logging.info(
"Got response code %s, content %s", response.status_code, response.content
)
if response.status_code == 200:
preds = json.loads(response.content.decode("utf-8"))
return preds
else:
response.raise_for_status()