<p>I use Kubernetes 1.6 and Docker to deploy instances/pods of a microservice.</p>

<p>I have a service that needs to regularly pull continuously updated data from an external repository. This update can be triggered manually on runtime, but the service is unusable during that time. Furthermore, the up-to-date data is always retrieved on startup, so that the freshly started service instance has the most recent external data.</p>

<p>Therefore, I would like to automatically create a fresh pod every hour (or some other frequency), and then kill the old pod.</p>

<p>Conceptually, it seems like I should just configure a maximum lifetime per pod in the deployment, so that Kubernetes starts a new instance/pod and kills the old one if the maximum lifetime has expired, while making sure that there is always at least on pod running.
However, <a href="https://github.com/kubernetes/kubernetes/issues/829" rel="noreferrer">Kubernetes does not seem to provide a maximum pod lifetime</a>.</p>

<p>Also, due to the data update during startup, starting the pod takes 1-2 minutes before it gets ready.</p>

<p>This meant to be as a comment but might become an answer. I am posting it as an answer so that the approach is easy to read.</p>

<p>So I have possible approach that might work for you. You run a global download pod which will download the files into specific folder. Let's assume download happens every 1 hour. So you will create a folder like <code>22-08-2017-20-00</code> and you create file called <code>latest</code>. The content of this <code>latest</code> file will be <code>22-08-2017-20-00</code></p>

<p>The downloader when it is fetching a new update, will create a new folder and download the data to same. Once the data is downloaded, it will change the content of the latest folder to that name.</p>

<p>Now your main app pods will refer to this host volumes, read the file content and use that folder to start the data processing. </p>

<p>Now you should run few replicas. If you setup a cron and restart the pods they will boot fast (no data download) and pickup the latest data. You can do a rolling update by changing a fake parameter with no impact and do a rolling update.</p>

<p>Or you can also set your pods to fail after 1 hour. How to do that? Make sure your image has the timeout command</p>

<pre><code>$ time timeout 2 sleep 12

real    0m2.002s
user    0m0.000s
sys 0m0.000s
</code></pre>

<p>Now you don't want all pods to fail at the same time, so you can generate a random number between 50min to 70min and let each pod fail at a different time and be restarted automatically by k8s</p>

<p>See if the approach makes any sense</p>
