<p>I have a Django app that is deployed on kubernetes. The container also has a mount to a persistent volume containing some files that are needed for operation. I want to have a check that will check that the files are there and accessible during runtime everytime a pod starts. The Django documentation recommends against running checks in production (the app runs in uwsgi), and because the files are only available in the production environment, the check will fail when unit tested.</p>
<p>What would be an acceptable process for executing the checks in production?</p>

<p>This is a community wiki answer posted for better visibility. Feel free to expand it.</p>
<p>Your use case can be addressed from Kubernetes perspective. All you have to do is to use the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-startup-probes" rel="nofollow noreferrer">Startup probes</a>:</p>
<blockquote>
<p>The kubelet uses startup probes to know when a container application
has started. If such a probe is configured, it disables liveness and
readiness checks until it succeeds, making sure those probes don't
interfere with the application startup. This can be used to adopt
liveness checks on slow starting containers, avoiding them getting
killed by the kubelet before they are up and running.</p>
</blockquote>
<p>With it you can use the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#execaction-v1-core" rel="nofollow noreferrer">ExecAction</a> that would execute a specified command inside the container. The diagnostic would be considered successful if the command exits with a status code of 0. An example of a simple command check could be one that checks if a particular file exists:</p>
<pre><code>    exec:
      command:
        - stat
        - /file_directory/file_name.txt
</code></pre>
<p>You could also use a shell script but remember that:</p>
<blockquote>
<p>Command is the command line to execute inside the container, the
working directory for the command is root ('/') in the container's
filesystem. The command is simply exec'd, it is not run inside a
shell, so traditional shell instructions ('|', etc) won't work. To use
a shell, you need to explicitly call out to that shell.</p>
</blockquote>
