在 Google Cloud Platform 安装

本指南介绍了如何在 Google Cloud 上运行的 Kubernetes 集群中设置和安装 Seldon Core。最终,您将能启动并运行 Seldon Core,并准备好部署机器学习模型。

要求

Google Cloud CLI

你需要 Google Cloud SDK 来检索集群验证凭证。它还可用于为您创建集群和其他资源:

Google Kubernetes Engine (GKE) 集群

如果您尚未在 GKE 上创建 Kubernetes 集群,则可以按照此快速入门指南设置您的第一个集群。确保创建 3 个节点 (--num-nodes 传递给 容器集群来创建) 以运行最小示例:

Warning

GKE 集群需要一个 标准 类型集群。GKE Autopilot 集群现在还不支持安装入口控制器。

Kubectl

kubectl 是 Kubernetes 命令行工具。它允许您对 Kubernetes 集群运行命令,这是设置 Seldon Core 的一部分。

Helm

Helm 是一个包管理工具,可以轻松查找、共享和使用为 Kubernetes 构建的软件。如果你还没有在本地安装 Helm,你可以在这里安装它:

连接到集群

运行 gcloud 命令连接到集群:

gcloud container clusters get-credentials CLUSTER_NAME

这将配置 kubectl 使用 google 云 kubernetes 集群。别忘记替换 CLUSTER_NAME 为你自己创建的集群。如果忘记,可以运行 gcloud container clusters list

Note

如果运行如上命令出现认证错误,尝试运行 gcloud auth login 来检查是否正确登录。

安装集群入口

Ingress 是为您的集群提供路由规则的 Kubernetes 对象。它管理传入的流量并将其路由到集群内运行的服务。

Seldon Core 支持使用 IstioAmbassador 来管理传入流量。Seldon Core 自动创建将流量路由到您部署的机器学习模型所需的对象和规则。

Istio 是一个开源服务网格。如果您对 service mesh 不熟悉,非常值得去阅读 更多关于Istio 的内容

下载 Istio

对于 Linux 及 macOS,最简单的方式是使用以下命令下载 Istio:

curl -L https://istio.io/downloadIstio | sh -

M进入 Istio 包目录。比如,包 istio-1.11.4

cd istio-1.11.4

添加 istioctl 客户端到 path (Linux or macOS):

export PATH=$PWD/bin:$PATH

安装 Istio

Istio 提供了一个命令工具 istioctl 来使安装更便捷。示例 配置项 有一组很好的默认值来运行在你本地集群。

istioctl install --set profile=demo -y

命名空间标签 istio-injection=enabled 指示 Istio 注入自动代理我们在该命名空间中部署的任何内容。我们将为我们的 default 命名空间设置它:

kubectl label namespace default istio-injection=enabled

创建 Istio 网关

为了让 Seldon Core 使用 Istio 的特性来管理流量,我们使用如下命令来创建一个 Istio Gateway

Warning

你需要拷贝下面全部的命令

kubectl apply -f - << END
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:
    - "*"
END

自定义配置及更多 seldon core 集成 Istio 安装的细节请查看 Istio 入口 页。

Ambassador 是 Kubernetes 入口控制器及 API 网关。他通过配置路由请求流量到 kubernetes 负载。

安装 Ambassador

Note

Seldon Core 现在只支持 Ambassador V1 APIs。以下安装说明将只安装 emissary ingress 最新的 v1 版本。

首先添加 datawire helm 仓库:

helm repo add datawire https://www.getambassador.io
helm repo update

执行以下 helm 命令安装 Ambassador 到 GKE 集群:

helm install ambassador datawire/ambassador --set enableAES=false --namespace ambassador --create-namespace
kubectl rollout status -n ambassador deployment/ambassador -w

Ambassador 已就绪。自定义配置及更多集成 Ambassador 安装 seldon core 的细节请查看 Ambassador 入口 页。

安装 Seldon Core

在安装 Seldon Core 前,创建一个 operator 运行所在的命名空间 seldon-system

kubectl create namespace seldon-system

现在我们已经为在集群安装 Seldon Core 准备就绪。根据选择的入口类型执行如下命令:

helm install seldon-core seldon-core-operator \
    --repo https://storage.googleapis.com/seldon-charts \
    --set usageMetrics.enabled=true \
    --set istio.enabled=true \
    --namespace seldon-system
helm install seldon-core seldon-core-operator \
    --repo https://storage.googleapis.com/seldon-charts \
    --set usageMetrics.enabled=true \
    --set ambassador.enabled=true \
    --namespace seldon-system

使用以下命令检查 Seldon Controller 运行状态:

kubectl get pods -n seldon-system

你应当看到 seldon-controller-manager pod 的状态 STATUS=Running

访问您的模型

恭喜!Seldon Core 现在已完全安装并运行。在继续部署模型之前,请记下您的集群 IP 和端口:

export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
export INGRESS_URL=$INGRESS_HOST:$INGRESS_PORT
echo $INGRESS_URL

这是您将用于访问集群中运行的模型的公共地址。

export INGRESS_HOST=$(kubectl -n ambassador get service ambassador -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n ambassador get service ambassador -o jsonpath='{.spec.ports[?(@.name=="http")].port}')
export INGRESS_URL=$INGRESS_HOST:$INGRESS_PORT
echo $INGRESS_URL

这是您将用于访问集群中运行的模型的公共地址。

您现在已准备好 将模型部署到您的集群