<p>I have a Kubernetes pod running Laravel but I get the following permission error on load:</p>
<p><a href="https://i.stack.imgur.com/zAidq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zAidq.png" alt="Permission denied" /></a></p>
<p>If I access the pod interactively and run chmod on /storage:</p>
<p><a href="https://i.stack.imgur.com/bidFk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bidFk.png" alt="chmod on storage" /></a></p>
<p>The laravel app works.  How can I get this command to run on deployment? I've tried the following but I get a 502 nginx error:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
    name: app
spec:
    replicas: 1
    selector:
        matchLabels:
            container: app
    template:
        metadata:
            labels:
                container: app
        spec:
            containers:
                - name: app
                  image: my/toolkit-app:test
                  command: [&quot;chmod -R 777 /storage&quot;]
                  securityContext:
                      runAsUser: 0
                  ports:
                      - containerPort: 80
            imagePullSecrets:
                - name: my-cred
</code></pre>

<p>You can use a <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks" rel="noreferrer">PostStart</a> Container hook.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
    name: app
spec:
    replicas: 1
    selector:
        matchLabels:
            container: app
    template:
        metadata:
            labels:
                container: app
        spec:
            containers:
                - name: app
                  image: my/toolkit-app:test
                  securityContext:
                      runAsUser: 0
                  ports:
                      - containerPort: 80
                  lifecycle:
                      postStart:
                          exec:
                              command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;chmod -R 777 /storage&quot;]
            imagePullSecrets:
                - name: my-cred
</code></pre>
<p>One thing consider:</p>
<blockquote>
<p>This hook is executed immediately after a container is created. However, there is no guarantee that the hook will execute before the container ENTRYPOINT. No parameters are passed to the handler.</p>
</blockquote>
