Kubeflow 部署(使用 kfctl_k8s_istio)
前期工作
该Kubeflow deployment要求 StorageClass 支持 dynamic volume provisioner。确认缺省的StorageClass的 provisioner
域的设置。如果换没有 provisioner, 确保配置了 volume provisioning,按照下面的描述在 Kubernetes cluster 进行设置(参考 below)。
Kubeflow依赖Istio的安装,参考:
使用 kfctl_k8s_istio.v1.0.2.yaml 配置安装,需要考虑下面的选项:
- Disabling istio installation - 如果 Kubernetes cluster 已有 Istio 安装,可以选择不安装Istio,通过一移除配置文件kfctl_k8s_istio.v1.0.2.yaml中的
istio-crds
和istio-install
参数。
准备环境
下载 kfctl 的 Kubeflow CLI 工具,然后手动设置环境变量:
-
下载kfctl v1.0.2 发布版本,到 Kubeflow releases page。
-
解压缩 tar ball:
tar -xvf kfctl_v1.0.2_<platform>.tar.gz
-
创建环境变量,简化部署过程:
# The following command is optional. It adds the kfctl binary to your path. # If you don't add kfctl to your path, you must use the full path # each time you run kfctl. # Use only alphanumeric characters or - in the directory name. export PATH=$PATH:"<path-to-kfctl>" ##实际如下: ##export PATH=$PATH:"/home/supermap/openthings/kubeflow" # Set KF_NAME to the name of your Kubeflow deployment. You also use this # value as directory name when creating your configuration directory. # For example, your deployment name can be 'my-kubeflow' or 'kf-test'. export KF_NAME=<your choice of name for the Kubeflow deployment> ##实际如下: ##export KF_NAME="kubeflow" # Set the path to the base directory where you want to store one or more # Kubeflow deployments. For example, /opt/. # Then set the Kubeflow application directory for this deployment. export BASE_DIR=<path to a base directory> export KF_DIR=${BASE_DIR}/${KF_NAME} ##实际如下: ##export BASE_DIR="/home/supermap/openthings/" ##export KF_DIR=${BASE_DIR}/${KF_NAME} # Set the configuration file to use when deploying Kubeflow. # The following configuration installs Istio by default. Comment out # the Istio components in the config file to skip Istio installation. # See https://github.com/kubeflow/kubeflow/pull/3663 export CONFIG_URI="https://raw.githubusercontent.com/kubeflow/manifests/v1.0-branch/kfdef/kfctl_k8s_istio.v1.0.2.yaml" ##实际如下: ##export CONFIG_URI=${BASE_DIR}/${KF_NAME}/kfctl_k8s_istio.v1.0.2.yaml
注意:
-
${KF_NAME} - Kubeflow 部署的名称。如果要定制部署的 deployment name,通过该参数指定。例如,
my-kubeflow
或kf-test
。该 KF_NAME 必须小写字母或者 ‘-', 开始和结束必须为字母。该变量不能超过 25 个字符。只能包含名称,不能包含目录路径。同时将作为创建目录的名称,用于保存 Kubeflow configurations,即Kubeflow application directory。 -
${KF_DIR} - Kubeflow application directory的全路径。
-
${CONFIG_URI} -该 GitHub address,位于 https://raw.githubusercontent.com/kubeflow/manifests/v1.0-branch/kfdef/kfctl_k8s_istio.v1.0.2.yaml。当运行
kfctl apply
或kfctl build
(see the next step), kfctl 创建一个 YAML 文件的本地版本,可以进一步定制化。
设置和部署 Kubeflow
使用缺省设置来设置和部署 Kubeflow using the default settings,运行 kfctl apply
如下:
mkdir -p ${KF_DIR}
cd ${KF_DIR}
kfctl apply -V -f ${CONFIG_URI}
检查 resources deployed in namespace kubeflow
:
kubectl -n kubeflow get all
可选,设置以后部署的配置参数:
在部署 Kubeflow时,如果需要定制安装参数,可以编辑该配置文件,然后运行 Kubeflow的部署命令即可:
-
运行
kfctl build
命令设置安装参数:mkdir -p ${KF_DIR} cd ${KF_DIR} kfctl build -V -f ${CONFIG_URI}
-
编辑配置文件,描述如上 customizing your Kubeflow deployment。
-
设置环境变量指向本地的配置文件:
export CONFIG_FILE=${KF_DIR}/kfctl_k8s_istio.v1.0.2.yaml
-
运行
kfctl apply
目录实施 Kubeflow 部署:kfctl apply -V -f ${CONFIG_FILE}
访问 Kubeflow 用户界面 (UI)
Kubeflow 部署完成后,Kubeflow Dashboard 的访问通过服务 istio-ingressgateway
来获取。loadbalancer在环境中不可用,NodePort 或 Port forwarding 可以用于访问 Kubeflow Dashboard,参考 Ingress Gateway guide 或者:
- 为私有Kubernetes集群创建LoadBalancer服务
- Kubernetes dashboard 通过 Ingress 提供HTTPS访问
- Kubernetes负载均衡器-Nginx ingress安装
删除 Kubeflow
运行下面的命令删除部署并回收资源:
cd ${KF_DIR}
# If you want to delete all the resources, run:
kfctl delete -f ${CONFIG_FILE}
理解部署过程
kfctl 部署过程包含下面几个命令:
kfctl build
- (可选) 创建配置文件,只在需要自行修改配置参数时才需要在kfctl apply之前运行
kfctl build
。kfctl apply
- 创建或更新资源。kfctl delete
- 删除资源。
应用的布局
您的 Kubeflow 应用目录 ${KF_DIR} 包含下面的文件和目录:
-
${CONFIG_FILE} 是一个 YAML 文件定义了kubeflow部署的参数:
- 该文件是 GitHub-based configuration YAML 文件的副本,位于: https://raw.githubusercontent.com/kubeflow/manifests/v1.0-branch/kfdef/kfctl_k8s_istio.v1.0.2.yaml,如果不能成功部署,需要先上github将其下载保存,然后修改URI指向到本地文件。
- 当运行
kfctl apply
或kfctl build
,kfctl 创建配置文件的本地副本${CONFIG_FILE}
, 然后可以对其编辑、客制化。
-
kustomize 是一个目录,包含 Kubeflow applications应用的定制化包。参考: how Kubeflow uses kustomize。
- 该目录在运行
kfctl build
或kfctl apply
时创建出来。 - 可以通过修改目录中的manifests来定制 Kubernetes resources ,然后重新运行
kfctl apply
进行部署和更新。
- 该目录在运行
建议将${KF_DIR}
目录中的内容纳入版本管理系统。
Provisioning of Persistent Volumes in Kubernetes
如果已经有 dynamic volume provisioner,可以跳过本步骤:
如果没有,参考:
- 在部署Kubeflow后手动创建 PVs 。
- 安装dynamic volume provisioner,如 Local Path Provisioner。确保provisioner使用的 StorageClass为缺省的 StorageClass。
问题解决
Persistent Volume Claims 处于 Pending 状态
检查PersistentVolumeClaims 是否 Bound
到 PersistentVolumes,如下:
kubectl -n kubeflow get pvc
如果PersistentVolumeClaims (PVCs) 在 Pending
状态,部署后没有bound 到 PersistentVolumes (PVs),就需要手动为每一个PVC创建PV,或者安装 dynamic volume provisioning 来按需创建PVs ,以及删除存在的PVCs然后重新部署 Kubeflow。