
4.3 Kubeflow 端到端的用户案例
上一节我们讲解了Kubeflow 的用户故事,本节我们运行一个Kubeflow 端到端的用户案例,并且讲解Kubeflow 中的关键组件。
需要特别说明的是,本节的目标只是使读者对Kubeflow 端到端的用户案例和关键组件有一个大致的了解,一些概念将在后面的章节详细讲解。运行Kubeflow 端到端的用户案例的步骤如下。
第一步,使用Jupyter Notebook 定义一个端到端的机器学习案例。
本节为了展示方便,只定义了超参调优、模型训练、服务发布共3 个主要环节。创建Jupyter Notebook 可以分为3 步,具体如下。
(1)安装并导入所需的Python 库。

(2)定义Pipelines,分为3 步,代码如下:







(3)将Pipelines 提交到Kubernetes 集群中运行。

第二步,通过浏览器访问Kubeflow 用户界面,如图4-2 所示。

图4-2 Kubeflow 用户界面
第三步,使用Notebook Servers Tab 创建一个Jupyter Notebook Server(在本案例中,Notebook 的镜像是gcr.io/kubeflow-images-public/tensorflow-1.14.0-notebook-cpu:v0.7.0),如图4-3 所示。

图4-3 创建Jupyter Notebook Server
第四步,访问并下载GitHub 的kubeflow/pipelines/samples/contrib/e2e-mnist/目录下的Notebook File 和测试图像,并且将Notebook File 上传到Kubeflow Jupyter Notebook Server上,如图4-4 所示。

图4-4 上传Notebook File
第五步,运行Notebook File,创建一个端到端的MNIST Pipelines,该Pipelines 包括使用Katib 进行超参调优,使用TFJob 进行模型训练,以及使用KFServing 发布服务等。
第六步,在运行Pipelines 时,可以通过单击run link 超链接查看Pipelines 的运行状态,如图4-5 所示。

图4-5 Pipelines 的运行状态
第七步,在Pipelines 运行完成后,在所有步骤中都会有一个绿色的图标。在Kubeflow Dashboard 中选择Katib → HP → Monitor tab 命令,可以查看使用Katib 进行超参调优的结果,如图4-6 所示。

图4-6 使用Katib 进行超参调优的结果