<p>I am working on a task where I need to design an ML pipeline for model retraining and inference on <code>Kubernetes</code></p>
<p>I read some articles and watched some tutorials, with the help of which I have created 2 apps as described below</p>
<ul>
<li>For Model retraining, I have scheduled a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">CronJob</a> (<code>Flask App #1</code>)</li>
<li>For inference, I have created a separate flask app (<code>Flask App #2</code>)</li>
</ul>
<p>I don't know how can we transfer the latest trained model from <code>CronJob</code> to the inference flask app</p>
<p>I am a newbie in Kubernetes any suggestion would be of great help</p>

arush1836
<p>We can make  use of the <strong>Google Persistent Disk</strong>, <strong><a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">Kubernetes Volume</a></strong> and <strong><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims" rel="nofollow noreferrer">Kubernetes Persistent Volume Claim</a></strong> to do so.</p>
<p>I tried replicating a scenario where a Cronjob updates a text file with current time and date each time it creates a Pod. I then created a separate Pod outside the Cronjob to access this text file and was successful. Below are the steps I followed,</p>
<ol>
<li><p>Create a Standard Persistent Disk on GCP using the following gcloud command,</p>
<pre><code>gcloud compute disks create pd-name   --size 500G   --type pd-standard   --zone us-central1-c
</code></pre>
</li>
<li><p>Then create a Kubernetes Persistent Volume using the above PD and a Persistent Volume Claim, so that the pods can request for storage on the Persistent Volume using the following configuration,</p>
</li>
</ol>
<p>config.yaml:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv
spec:
  storageClassName: &quot;test&quot;
  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: &quot;test&quot;
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10G  
</code></pre>
<ol start="3">
<li>Deploy a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">Cronjob</a> with the PVC configuration and which writes the current time and date into a text file stored on the PV using the following configuration,</li>
</ol>
<p>Cronjob.yaml:</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cron
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          volumes:
            - name: pv-storage
              persistentVolumeClaim:
                claimName: pv-claim
          containers:
            - name: container
              image: nginx
              volumeMounts:
                - mountPath: &quot;/usr/data&quot;
                  name: pv-storage
              command:
              - /bin/sh
              - -c
              - date &gt;&gt; /usr/data/msg.txt
          restartPolicy: OnFailure
</code></pre>
<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">Configure a Pod to Use a PersistentVolume for Storage</a> for more information.</p>
<ol start="4">
<li>Deploy a Pod with the same PVC configuration to check whether data added by the Cronjob pods is visible through this pod using the following configuration,</li>
</ol>
<p>Readpod.yaml:</p>
<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: readpod
spec:
  volumes:
    - name: pv-storage
      persistentVolumeClaim:
       claimName: pv-claim
  containers:
    - name: read-container
      image: nginx
      volumeMounts:
        - mountPath: &quot;/usr/data&quot;
          name: pv-storage
</code></pre>
<ol start="5">
<li><p>Then use <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/" rel="nofollow noreferrer">kubectl exec</a> command to get a shell to a running container on the above Pod, by using the following commands and we should be able to view the text file in which the cronjob was updating time and date.</p>
<pre><code>     $ kubectl exec -it  readpod -- /bin/bash
     $ cd usr/data
     $ cat msg.txt
</code></pre>
</li>
</ol>
<p>You can make use of the above concepts and modify the configuration according to your use case.</p>
