As far as I know, there is no “official” way to do it the way you want, and I consider this by design. It is assumed that the Pods will be ephemeral and horizontally scalable, and Jobs is intended to exit. The presence of a cron job for an existing container does not match this module. The scheduler had no idea if the work was completed.
Instead, Job can call an instance of your application specifically to run the job and then take it off after the job is completed. To do this, you can use the same image for the job as for the deployment, but use a different “entry point” by setting command:
If they need access to the data created by your application, then this data must be stored outside the application / Pod, you could do this in several ways, but the obvious way would be a database or a persistent volume. For example, using a database would look something like this:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: APP spec: template: metadata: labels: name: THIS app: THAT spec: containers: - image: APP:IMAGE name: APP command: - app-start env: - name: DB_HOST value: "127.0.0.1" - name: DB_DATABASE value: "app_db"
And a job that connects to one database, but with a different "entry point":
apiVersion: batch/v1 kind: Job metadata: name: APP-JOB spec: template: metadata: name: APP-JOB labels: app: THAT spec: containers: - image: APP:IMAGE name: APP-JOB command: - app-job env: - name: DB_HOST value: "127.0.0.1" - name: DB_DATABASE value: "app_db"
Or a constant-volume approach would look something like this:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: APP spec: template: metadata: labels: name: THIS app: THAT spec: containers: - image: APP:IMAGE name: APP command: - app-start volumeMounts: - mountPath: "/var/www/html" name: APP-VOLUME volumes: - name: APP-VOLUME persistentVolumeClaim: claimName: APP-CLAIM
With this task attached to the same thing:
apiVersion: batch/v1 kind: Job metadata: name: APP-JOB spec: template: metadata: name: APP-JOB labels: app: THAT spec: containers: - image: APP:IMAGE name: APP-JOB command: - app-job volumeMounts: - mountPath: "/var/www/html" name: APP-VOLUME volumes: - name: APP-VOLUME persistentVolumeClaim: claimName: APP-CLAIM
Simon i
source share