<p>I have a Neo4j service, but before the deployment starts up, I need to pre-fill it with data (about 2GB of data). Currently, I wrote a Kubernetes <code>Job</code> to transform the data from a CSV and format it for the database using the <code>neo4j-admin</code> tool. It saves the formatted data to a <em>persistent volume</em>. After waiting for the job to complete, I mount the volume in the Neo4j container and the container is effectively read-only on this data for the rest of its life. </p>

<p><strong>Is there a better way to do this more automatically?</strong></p>

<p>I don't want to have to wait for the job to complete to run another command to create the Neo4j deployment. I looked into initContainers, but that isn't suitable because I don't want to redo the data filling when a pod is re-created. I just want subsequent pods to read from the same persistent volume. Is there a way to wait for the job to complete first?</p>

Andy Carlson
<p>As Jobs can't natively spawn new objects once finished (and if exited gracefully, using <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks" rel="nofollow noreferrer">PreStop</a> to invoke further actions won't work), you might want to monitor the API objects instead.</p>

<p><a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#programmatic-access-to-the-api" rel="nofollow noreferrer">Programatically accessing the API</a> to determine when the Job is finished and then, <a href="https://github.com/kubernetes/client-go/tree/master/examples/create-update-delete-deployment" rel="nofollow noreferrer">create your Deployment object</a> might be a feasible, automated way to do it.</p>

<p>Doing it this way, you don't have to worry for redoing the data processing with <em>initContainers</em> as you can essentially call the deployment and remount the already existing volume.</p>

<p>Also, using the <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-supported-kubernetes-client-libraries" rel="nofollow noreferrer">official Go library</a> allows you to either <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-supported-kubernetes-client-libraries" rel="nofollow noreferrer">run within the cluster, in a pod or externally</a>.</p>
