【问题标题】:How to create an ML pipeline for model retraining and inference [Kubernetes]如何为模型再训练和推理创建 ML 管道 [Kubernetes]
【发布时间】:2021-10-05 18:58:31
【问题描述】:

我正在处理一项任务,我需要在 Kubernetes 上设计一个用于模型再训练和推理的 ML 管道

我阅读了一些文章并观看了一些教程,在这些教程的帮助下我创建了如下所述的 2 个应用程序

  • 对于模型再训练,我已经安排了CronJob (Flask App #1)
  • 为了推断,我创建了一个单独的烧瓶应用程序 (Flask App #2)

我不知道我们如何将最新的训练模型从CronJob 转移到推理烧瓶应用程序

我是 Kubernetes 的新手,任何建议都会有很大帮助

【问题讨论】:

    标签: python flask kubernetes google-cloud-platform kubernetes-cronjob


    【解决方案1】:

    我们可以使用 Google Persistent DiskKubernetes VolumeKubernetes Persistent Volume Claim 来做到这一点。

    我尝试复制一个场景,其中 Cronjob 每次创建 Pod 时都会使用当前时间和日期更新文本文件。然后我在 Cronjob 之外创建了一个单独的 Pod 来访问这个文本文件并且成功了。以下是我遵循的步骤,

    1. 使用以下 gcloud 命令在 GCP 上创建标准永久磁盘,

      gcloud compute disks create pd-name   --size 500G   --type pd-standard   --zone us-central1-c
      
    2. 然后使用上述 PD 和 Persistent Volume Claim 创建 Kubernetes Persistent Volume,以便 pod 可以使用以下配置请求 Persistent Volume 上的存储,

    config.yaml:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv
    spec:
      storageClassName: "test"
      capacity:
        storage: 10G
      accessModes:
        - ReadWriteOnce
      claimRef:
        namespace: default
        name: pv-claim
      gcePersistentDisk:
        pdName: pd-name
        fsType: ext4
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pv-claim
    spec:
      storageClassName: "test"
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 10G  
    
    1. 使用 PVC 配置部署 Cronjob,并使用以下配置将当前时间和日期写入存储在 PV 上的文本文件中,

    Cronjob.yaml:

    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
      name: cron
    spec:
      schedule: "*/1 * * * *"
      jobTemplate:
        spec:
          template:
            spec:
              volumes:
                - name: pv-storage
                  persistentVolumeClaim:
                    claimName: pv-claim
              containers:
                - name: container
                  image: nginx
                  volumeMounts:
                    - mountPath: "/usr/data"
                      name: pv-storage
                  command:
                  - /bin/sh
                  - -c
                  - date >> /usr/data/msg.txt
              restartPolicy: OnFailure
    

    Configure a Pod to Use a PersistentVolume for Storage 了解更多信息。

    1. 部署具有相同 PVC 配置的 Pod,使用以下配置检查 Cronjob pod 添加的数据是否通过该 pod 可见,

    Readpod.yaml:

    kind: Pod
    apiVersion: v1
    metadata:
      name: readpod
    spec:
      volumes:
        - name: pv-storage
          persistentVolumeClaim:
           claimName: pv-claim
      containers:
        - name: read-container
          image: nginx
          volumeMounts:
            - mountPath: "/usr/data"
              name: pv-storage
    
    1. 然后使用kubectl exec 命令获取上述 Pod 上正在运行的容器的 shell,通过使用以下命令,我们应该能够查看 cronjob 正在更新时间和日期的文本文件。

           $ kubectl exec -it  readpod -- /bin/bash
           $ cd usr/data
           $ cat msg.txt
      

    您可以利用上述概念,根据您的用例修改配置。

    【讨论】:

      猜你喜欢
      • 2019-03-16
      • 2017-12-31
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多