<p>I'm currently working on a Lumen project where we are using Minikube as our dev environment. Our host machine's <code>/Users/development/&lt;project name&gt;</code> is mounted at <code>/var/www/html</code> and is working fine.
However, I'm facing this Storage issue where file writes are not working in the <code>/var/www/html/storage/framework</code> due to the fact that the entire <code>/var/www/html</code> directory has the <strong>1001:1001</strong> ownership.</p>

<p>This is my deployment spec:</p>

<pre><code>apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: apiserver
  namespace: development
  labels:
    app: sample-app-name
spec:
  selector:
    matchLabels:
      app: sample-app-name
      tier: apiserver
  replicas: 1
  template:
    metadata:
      labels:
        app: sample-app-name
        tier: apiserver
    spec:
      containers:
      - name: php-app
        image: my-image:latest
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        imagePullPolicy: Never
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - containerPort: 80
        volumeMounts:
          - mountPath: "/var/www/html"
            name: host-mount
      imagePullSecrets:
        - name: dockercred
      volumes:
      - name: host-mount
        hostPath:
          path: "/Users/development/&lt;app directory&gt;"
</code></pre>

<p>I tried moving the persistent volume onto its own separate file, and had created a pvc, but still, it's not working.
I also tried multiple ways on how to change the directory permissions using both init containers and security context, but it still the permissions are always set to **1001:1001*
I'm really desperate here, so any help would be appreciated.</p>

<p>Host specs:</p>

<ul>
<li>OS: Ubuntu 18.04.3 LTS</li>
<li>Minikube Version: v0.30.0</li>
<li>Kubectl Client Version: Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}</li>
<li>Kubectl Server Version: Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}</li>
<li>Virtualbox Version: 5.2.34 r133893 (Qt5.9.5)</li>
</ul>

<p><strong>EDIT:</strong> (Here's docker file of the image i'm using in the Deployment)</p>

<pre><code>FROM phpearth/php:7.1-nginx

RUN apk add --no-cache php7.1-redis php7.1-pdo php7.1-pdo_pgsql php7.1-xdebug composer bash

COPY ./nginx-default.conf /etc/nginx/conf.d/default.conf
COPY ./xdebug.ini /etc/php/7.1/conf.d/xdebug.ini
COPY ./www.conf /etc/php/7.1/php-fpm.d/www.conf
RUN mkdir -p /var/www/storage/import
RUN mkdir -p /var/www/storage/import/files
RUN mkdir -p /var/www/storage/import/templates
RUN mkdir -p /var/www/storage/logs
RUN mkdir -p /var/www/storage/framework/sessions
RUN mkdir -p /var/www/storage/framework/views
RUN touch /var/www/storage/logs/lumen.log
RUN chown -Rf 1000:1000 /var/www/
# Install the blackfire client
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    &amp;&amp; curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s http://packages.blackfire.io/binaries/blackfire-php/1.23.1/blackfire-php-alpine_amd64-php-71.tar.gz \
    &amp;&amp; mkdir -p /tmp/blackfire \
    &amp;&amp; tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    &amp;&amp; mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
    &amp;&amp; printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" &gt; /etc/php/7.1/conf.d/blackfire.ini \
    &amp;&amp; rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

</code></pre>

Dreadnaut
<p>Turns out, this wasn't a mounting issue. I kept blaming the <code>hostPath</code> mount
because when I try running <code>ls -lah</code> on <em>/var/www</em>, it kept showing the <em>html</em> directory's permissions as <strong>1001:1001</strong> instead of www-data.</p>

<p>In the end, it was PHP's user that wasn't running on the correct UID.
Dumping <code>posix_getpwuid(posix_geteuid())</code> shows the following result:</p>

<pre><code>array:7 [
  "name" =&gt; "www-data"
  "passwd" =&gt; "x"
  "uid" =&gt; 82
  "gid" =&gt; 82
  "gecos" =&gt; "www-data"
  "dir" =&gt; "/var/www"
  "shell" =&gt; "/sbin/nologin"
]
</code></pre>

<p>But after adding this line in my Dockerfile:
<code>RUN apk add shadow &amp;&amp; usermod -u 1000 www-data &amp;&amp; groupmod -g 1000 www-data</code>, it now shows this:</p>

<pre><code>array:7 [
  "name" =&gt; "www-data"
  "passwd" =&gt; "x"
  "uid" =&gt; 1000
  "gid" =&gt; 1000
  "gecos" =&gt; "www-data"
  "dir" =&gt; "/var/www"
  "shell" =&gt; "/sbin/nologin"
]
</code></pre>

<p>I'm not having any permission issues now on my APIs.</p>
