<p>I have a Kubernetes Deployment, in whose Pods I need a command run periodically.
The Kubernetes <code>CronJob</code> object creates a new Pod.
I would prefer to specify a cronjob, that runs inside the container of the Pod.
Is there any way, I can specify this in the deployment yaml?</p>
<p>I have no access to the Dockerfile, but am using pre-built Images.</p>

sekthor
<p>You can try as into <code>deploy.yaml</code>, where this job will run on 25th of every month and copy <code>app.xml</code> file to the <code>/mount</code> directory of the <code>PersistentVolume</code> on <code>Kubernetes Cluster</code> as below:-</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: app-feed-fio
spec:
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 100Gi
  storageClassName: fileshare
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-fio-scripts
data:
  appupdater.sh: |
    #!/bin/bash
    set -e
    set -x

    curl https://example.com/xyz.xml -o /mount/app.xml -v

    ls -la /mount

    cat /mount/app.xml

---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: app-feed-job
spec:
  schedule: &quot;00 00 25 * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          securityContext:
            runAsNonRoot: true
            runAsUser: 1500
            fsGroup: 1500
    #        supplementalGroups: [0]
          restartPolicy: OnFailure
          containers:
          - name: appupdater
            image: {container registry path}/app-feed-fio:v0.0.0
            command: [&quot;/scripts/appupdater.sh&quot;]
            resources:
              requests:
                memory: 100Mi
                cpu: 0.1
              limits:
                memory: 100Mi
                cpu: 0.1
            volumeMounts:
            - mountPath: /mount
              name: fileshare        
            - mountPath: /scripts
              name: scripts    
          volumes:
          - name: fileshare
            persistentVolumeClaim:
              claimName: app-fio-pvc
          - name: scripts
            configMap:
              name: app-fio-scripts
              defaultMode: 0777
</code></pre>
<p>And, in <code>Dockerfile</code> as below:-</p>
<pre><code>from ubuntu:focal
run apt-get -y update &amp;&amp; \
    apt-get install -y fio curl &amp;&amp; \
    apt-get autoremove --purge &amp;&amp; \
    apt-get clean &amp;&amp; \
    mkdir /mount &amp;&amp; \
    groupadd -g 1500 fio &amp;&amp; \
    useradd -u 1500 -g 1500 fio

user 1500:1500
volume /mount
</code></pre>
