上一篇, 我們已使用 xgboost 完成訓練並且產生model檔, 這個model的檔名為bst_save_model.pkl
現在我們來到了第二個範例的第三個步驟:serving
, 如下圖所示.
這次我們要使用seldon部署我們的模型. Seldon是最近很熱門的model部署工具, 它建立在kubernetes平台上, 也因為我們在第二天就已經安裝好一個K8s cluster, 所以要安裝seldon core是一件很方便的事.
Seldon core的官網在這裡: https://www.seldon.io/tech/products/core/
首先, 我們來安裝istio, 因為我們在安裝seldon時會啟用istio.
下載istio
$curl -L https://istio.io/downloadIstio | sh -
設定PATH
$cd istio-1.11.1 #版本號要根據下載的版本做修改
$export PATH=$PWD/bin:$PATH
開始安裝
$kubectl create namespace istio-system
$helm install istio-base manifests/charts/base -n istio-system
$helm install istiod manifests/charts/istio-control/istio-discovery -n istio-system
$helm install istio-ingress manifests/charts/gateways/istio-ingress -n istio-system
$helm install istio-egress manifests/charts/gateways/istio-egress -n istio-system
建立seldon GATEWAY
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: seldon-gateway
namespace: istio-system
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
建立seldon所使用的namespace
kubectl create namespace seldon-system
執行helm指令安裝seldon
ps: 我們在Day4 安裝JupyterHub
已安裝過hlem
helm install seldon-core seldon-core-operator \
--repo https://storage.googleapis.com/seldon-charts \
--set usageMetrics.enabled=true \
--namespace seldon-system \
--set istio.enabled=true \
--set istio.gateway=istio-system/seldon-gateway
執行完成的訊息如下:
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.5a" from https://storage.googleapis.com/seldon-charts: validation: chart.metadata.version "0.1.5a" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.6_SNAPSHOT" from https://storage.googleapis.com/seldon-charts: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.6_SNAPSHOT" from https://storage.googleapis.com/seldon-charts: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core" "0.1.6_SNAPSHOT" from https://storage.googleapis.com/seldon-charts: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core" "0.1.6_SNAPSHOT" from /home/k8s/.cache/helm/repository/E3xhv-3+r1pSeDV8I8nqHo7tIjk=-index.yaml: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.5a" from /home/k8s/.cache/helm/repository/E3xhv-3+r1pSeDV8I8nqHo7tIjk=-index.yaml: validation: chart.metadata.version "0.1.5a" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.6_SNAPSHOT" from /home/k8s/.cache/helm/repository/E3xhv-3+r1pSeDV8I8nqHo7tIjk=-index.yaml: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
index.go:339: skipping loading invalid entry for chart "seldon-core-crd" "0.1.6_SNAPSHOT" from /home/k8s/.cache/helm/repository/E3xhv-3+r1pSeDV8I8nqHo7tIjk=-index.yaml: validation: chart.metadata.version "0.1.6_SNAPSHOT" is invalid
W0913 11:51:43.488868 16657 warnings.go:70] rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole
W0913 11:51:43.506167 16657 warnings.go:70] rbac.authorization.k8s.io/v1beta1 ClusterRoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRoleBinding
W0913 11:51:43.676157 16657 warnings.go:70] admissionregistration.k8s.io/v1beta1 ValidatingWebhookConfiguration is deprecated in v1.16+, unavailable in v1.22+; use admissionregistration.k8s.io/v1 ValidatingWebhookConfiguration
W0913 11:51:48.918777 16657 warnings.go:70] rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole
W0913 11:51:48.988508 16657 warnings.go:70] rbac.authorization.k8s.io/v1beta1 ClusterRoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRoleBinding
W0913 11:51:50.531620 16657 warnings.go:70] admissionregistration.k8s.io/v1beta1 ValidatingWebhookConfiguration is deprecated in v1.16+, unavailable in v1.22+; use admissionregistration.k8s.io/v1 ValidatingWebhookConfiguration
NAME: seldon-core
LAST DEPLOYED: Mon Sep 13 11:51:37 2021
NAMESPACE: seldon-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
k8s@k8s-master:~/mlops$
因為使用seldon部署model時需要將model放在下列四種儲存空間的其中一種:
除了上述4個環境, 還可以使用pvc, 在這個網頁有一行這麼寫A Kubernetes PersistentVolume can be used instead of a bucket using pvc://.
我們先使用pvc空間做一次, 之後再使用MinIO做一次.
而且在我們的K8s環境中原本就有一個NFS空間, 之前是讓JupyterHub使用, 現在我們就再使用NFS空間建立pvc放置要部署在seldon上的模型檔案.
請撰寫下列yaml內容. 請注意, 這個的storageClassName必需是已經存在的名稱, 因為我們在安裝JupyterHub就建立過storage class, 名稱即是nfs-client
. 如果你沒有這個storage class, 那你要先建立一個.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: seldon-pv-claim
spec:
storageClassName: nfs-client
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
將這個yaml檔存為seldon-pvc.yaml
所以執行下列指令, 這樣我們就準備好所需要的空間.
$kubectl apply -f seldon-pvc.yaml
你也可以在github下載這個檔案
到這裡我們就準備好所需要的環境, 下一篇我們就來把訓練好的模型使用seldon部署起來
https://istio.io/latest/docs/setup/getting-started/#download
https://istio.io/latest/docs/setup/install/helm/
https://docs.seldon.io/projects/seldon-core/en/v1.9.1/workflow/github-readme.html