千家信息网

如何部署Ubuntu20.04 + k8s 1.21.0开发环境

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这篇文章主要为大家展示了"如何部署Ubuntu20.04 + k8s 1.21.0开发环境",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何部署Ubunt
千家信息网最后更新 2025年12月02日如何部署Ubuntu20.04 + k8s 1.21.0开发环境

这篇文章主要为大家展示了"如何部署Ubuntu20.04 + k8s 1.21.0开发环境",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何部署Ubuntu20.04 + k8s 1.21.0开发环境"这篇文章吧。

Kubeflow 部署(使用 kfctl_k8s_istio)

安装 Kubeflow的一些指南(使用 kfctl_k8s_istio 配置部署到已有的Kubernetes集群中)。该配置清单创建Kubeflow的核心部件部署,但不包括外部依赖,可以根据您的环境需要进行优化。KubeFlow 1.2.0部署到Ubuntu20.04和k8s 1.21.0,其它平台可能有些变化。

该Kubeflow deployment要求 StorageClass 支持 dynamic volume provisioner。确认缺省的StorageClass的 provisioner 域的设置。如果换没有 provisioner, 确保配置了 volume provisioning,按照下面的描述在 Kubernetes cluster 进行设置(参考 below)。

使用 kfctl_k8s_istio.v1.2.0.yaml 配置安装,需要考虑下面的选项:

  • Disabling istio installation - 如果 Kubernetes cluster 已有 Istio 安装,可以选择不安装Istio,通过一移除配置文件kfctl_k8s_istio.v1.0.2.yaml中的 istio-crdsistio-install 参数。

准备环境

下载 kfctl 的 Kubeflow CLI 工具,然后手动设置环境变量:

  • 下载kfctl v1.2.0 发布版本,到 Kubeflow releases page。

wget https://github.com/kubeflow/kfctl/releases/download/v1.2.0/kfctl_v1.2.0-0-gbc038f9_linux.tar.gztar -vxf kfctl_v1.2.0-0-gbc038f9_linux.tar.gzsudo cp kfctl /usr/bin/
  • 创建环境变量,简化部署过程:

# 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:""##实际如下:##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=##实际如下:##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=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/3663export CONFIG_URI="https://raw.githubusercontent.com/kubeflow/manifests/v1.2-branch/kfdef/kfctl_k8s_istio.v1.2.0.yaml"##实际如下:##export CONFIG_URI=${BASE_DIR}/${KF_NAME}/kfctl_k8s_istio.v1.2.0.yaml

注意:

  • ${KF_NAME} - Kubeflow 部署的名称。如果要定制部署的 deployment name,通过该参数指定。例如, my-kubeflowkf-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.2-branch/kfdef/kfctl_k8s_istio.v1.2.0.yaml。当运行kfctl applykfctl build (see the next step), kfctl 创建一个 YAML 文件的本地版本,可以进一步定制化。

⚠️注意:

  • 运行kfctl build或apply -V -f xxx时,出现manifest下载不成功,可以将其下载下来,然后修改kfctl_k8s_istio.v1.2.0.yaml的下面内容,将manifest指向本地路径。如下:

  repos:  - name: manifests    uri: /home/supermap/openthings/kubeflow/v1.2.0.tar.gz  version: v1.2-branch

设置和部署 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的部署命令即可:

  1. 运行 kfctl build 命令设置安装参数:

    mkdir -p ${KF_DIR}cd ${KF_DIR}kfctl build -V -f ${CONFIG_URI}


  2. 编辑配置文件,描述如上 customizing your Kubeflow deployment。

  3. 设置环境变量指向本地的配置文件:

    export CONFIG_FILE=${KF_DIR}/kfctl_k8s_istio.v1.2.0.yaml


  4. 运行 kfctl apply 目录实施 Kubeflow 部署:

    kfctl apply -V -f ${CONFIG_FILE}


出现错误:

2021/04/28 10:24:44 absolute path error in '/home/supermap/openthings/kubeflow/.cache/manifests/namespaces/base' : evalsymlink failure on '/home/supermap/openthings/kubeflow/.cache/manifests/namespaces/base' : lstat /home/supermap/openthings/kubeflow/.cache/manifests/namespaces: no such file or directoryERRO[0000] Error evaluating kustomization manifest for namespaces: accumulating resources: accumulating resources from '../../.cache/manifests/namespaces/base': open /home/supermap/openthings/kubeflow/.cache/manifests/namespaces/base: no such file or directory  filename="kustomize/kustomize.go:155"Error: failed to apply:  (kubeflow.error): Code 500 with message: kfApp Apply failed for kustomize:  (kubeflow.error): Code 500 with message: error evaluating kustomization manifest for namespaces: accumulating resources: accumulating resources from '../../.cache/manifests/namespaces/base': open /home/supermap/openthings/kubeflow/.cache/manifests/namespaces/base: no such file or directory
  • 查看.cache目录,发现manifest位于 ~/openthings/kubeflow/.cache/manifests/manifests-1.2.0 目录下,而不是上面的manifests目录。

  • 将manifests-1.2.0下的所有文件移到上一级即manifest目录下,再次运行kfctl apply。如下:

cd manifests-1.2.0mv -r * ../
  • 但是运行kfctl apply发现会将.cache目录删除,导致上面的复制方法失效。

  • 直接修改配置文件,修改所有自定义资源的路径,改完后的配置文件如下:

apiVersion: kfdef.apps.kubeflow.org/v1kind: KfDefmetadata:  creationTimestamp: null  namespace: kubeflowspec:  applications:  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/namespaces/base    name: namespaces  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/application/v3    name: application  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/istio-1-3-1-stack    name: istio-stack  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/cluster-local-gateway-1-3-1    name: cluster-local-gateway  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/istio/istio/base    name: istio  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/cert-manager-crds    name: cert-manager-crds  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/cert-manager-kube-system-resources    name: cert-manager-kube-system-resources  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/add-anonymous-user-filter    name: add-anonymous-user-filter  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/metacontroller/base    name: metacontroller  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/admission-webhook/bootstrap/overlays/application    name: bootstrap  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/spark-operator    name: spark-operator  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes    name: kubeflow-apps  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/knative/installs/generic    name: knative  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/kfserving/installs/generic    name: kfserving  - kustomizeConfig:      repoRef:        name: manifests        path: manifests-1.2.0/stacks/kubernetes/application/spartakus    name: spartakus  repos:  - name: manifests    uri: /home/supermap/openthings/kubeflow/v1.2.0.tar.gz  version: v1.2-branchstatus: {}
  • 删除kustomize目录,重新运行kfctl build和kfctl apply.

KubeFlow的镜像较多,完全启动需要比较长的时间,需要耐心等待。

过段时间看,有些pod已经启动起来了,主界面已经可以访问了。

查看状态,有些镜像和服务有问题,包括镜像下载、存储卷设置等,留待后续解决。

(base) supermap@xriver02:~$ kubectl get pod -n kubeflowNAME                                                     READY   STATUS             RESTARTS   AGEadmission-webhook-bootstrap-stateful-set-0               0/1     ImagePullBackOff   0          36hadmission-webhook-deployment-5cd7dc96f5-l9rxl            1/1     Running            0          36happlication-controller-stateful-set-0                    0/1     ImagePullBackOff   0          36hargo-ui-657cf69ff5-kn966                                 1/1     Running            0          36hcache-deployer-deployment-5f4979f45-q6psq                1/2     ImagePullBackOff   0          36hcache-server-7859fd67f5-kx8zm                            0/2     Init:0/1           0          36hcentraldashboard-86744cbb7b-44rbc                        1/1     Running            0          36hjupyter-web-app-deployment-8486d5ffff-9czzl              1/1     Running            0          36hkatib-controller-7fcc95676b-tsbzx                        1/1     Running            1          36hkatib-db-manager-67867f5498-jzrgh                        0/1     Running            442        36hkatib-mysql-6b5d848bf5-gs95h                             0/1     Pending            0          36hkatib-ui-65dc4cf6f5-pqj5p                                1/1     Running            0          36hkfserving-controller-manager-0                           1/2     ImagePullBackOff   0          36hkubeflow-pipelines-profile-controller-797fb44db9-vznlv   1/1     Running            0          36hmetacontroller-0                                         1/1     Running            0          36hmetadata-db-c65f4bc75-m2ggv                              0/1     Pending            0          36hmetadata-envoy-deployment-67bd5954c-jl7pn                1/1     Running            0          36hmetadata-grpc-deployment-577c67c96f-29dwx                0/1     CrashLoopBackOff   433        36hmetadata-writer-756dbdd478-tlrpw                         2/2     Running            325        36hminio-54d995c97b-jrmqq                                   0/1     Pending            0          36hml-pipeline-8d6749d9c-drv2h                              1/2     CrashLoopBackOff   662        36hml-pipeline-persistenceagent-d984c9585-mhstn             2/2     Running            0          36hml-pipeline-scheduledworkflow-5ccf4c9fcc-wqg4d           2/2     Running            0          36hml-pipeline-ui-8ccbf585c-77krb                           2/2     Running            0          36hml-pipeline-viewer-crd-56c68f6c85-bssgc                  1/2     ImagePullBackOff   0          36hml-pipeline-visualizationserver-7446b96877-ffs7b         2/2     Running            0          36hmpi-operator-d5bfb8489-75m6b                             1/1     Running            0          36hmxnet-operator-7576d697d6-jwks8                          1/1     Running            0          36hmysql-74f8f99bc8-ndzqg                                   0/2     Pending            0          36hnotebook-controller-deployment-dd4c74b47-k9fng           0/1     ImagePullBackOff   0          36hprofiles-deployment-65f54cb5c4-9xtws                     0/2     ImagePullBackOff   0          36hpytorch-operator-847c8d55d8-x6l4t                        0/1     ImagePullBackOff   0          36hseldon-controller-manager-6bf8b45656-d7rvf               1/1     Running            0          36hspark-operatorsparkoperator-fdfbfd99-cst9l               0/1     ImagePullBackOff   0          36hspartakus-volunteer-558f8bfd47-tcvpn                     1/1     Running            0          36htf-job-operator-58477797f8-wr79t                         1/1     Running            0          36hworkflow-controller-64fd7cffc5-m6gkc                     1/1     Running            0          36h

访问 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 applykfctl build,kfctl 创建配置文件的本地副本 ${CONFIG_FILE}, 然后可以对其编辑、客制化。

  • kustomize 是一个目录,包含 Kubeflow applications应用的定制化包。参考: how Kubeflow uses kustomize。

    • 该目录在运行 kfctl buildkfctl apply时创建出来。

    • 可以通过修改目录中的manifests来定制 Kubernetes resources ,然后重新运行 kfctl apply 进行部署和更新。

建议将${KF_DIR} 目录中的内容纳入版本管理系统。

Provisioning of Persistent Volumes in Kubernetes

如果已经有 dynamic volume provisioner,可以跳过本步骤

问题解决

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。

以上是"如何部署Ubuntu20.04 + k8s 1.21.0开发环境"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

0