<p>I am facing an error while deploying Airflow on Kubernetes (precisely this version of Airflow <a href="https://github.com/puckel/docker-airflow/blob/1.8.1/Dockerfile" rel="noreferrer">https://github.com/puckel/docker-airflow/blob/1.8.1/Dockerfile</a>) regarding writing permissions onto the filesystem.</p>

<p>The error displayed on the logs of the pod is:</p>

<pre><code>sed: couldn't open temporary file /usr/local/airflow/sed18bPUH: Read-only file system
sed: -e expression #1, char 131: unterminated `s' command
sed: -e expression #1, char 118: unterminated `s' command
Initialize database...
sed: couldn't open temporary file /usr/local/airflow/sedouxZBL: Read-only file system
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/airflow/configuration.py", line 769, in
    ....
    with open(TEST_CONFIG_FILE, 'w') as f:
IOError: [Errno 30] Read-only file system: '/usr/local/airflow/unittests.cfg'
</code></pre>

<p>It seems that the filesystem is read-only but I do not understand why it is. I am not sure if it is a <strong>Kubernetes misconfiguration</strong> (do I need a special RBAC for pods ? No idea) or if it is a problem with the <strong>Dockerfile</strong>. </p>

<p>The deployment file looks like the following:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: airflow
  namespace: test
spec:
  replicas: 1
  revisionHistoryLimit: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  template:
    metadata:
      labels:
        app: airflow
    spec:
      restartPolicy: Always
      containers:
      - name: webserver
        image: davideberdin/docker-airflow:0.0.4
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 1
            memory: 1Gi
          requests:
            cpu: 50m
            memory: 128Mi
        securityContext:  #does not have any effect
          runAsUser: 0    #does not have any effect
        ports:
        - name: airflow-web
          containerPort: 8080
        args: ["webserver"]
        volumeMounts:
          - name: airflow-config-volume
            mountPath: /usr/local/airflow
            readOnly: false #does not have any effect
          - name: airflow-logs
            mountPath: /usr/local/logs
            readOnly: false #does not have any effect
      volumes:
      - name: airflow-config-volume
        secret:
          secretName: airflow-config-secret
      - name: airflow-parameters-volume
        secret:
          secretName: airflow-parameters-secret
      - name: airflow-logs
        emptyDir: {}
</code></pre>

<p>Any idea how I can make the filesystem writable? The container is running as <strong>USER airflow</strong> but I think that this user has root privileges.</p>

<p>Since kubernetes version 1.9 and forth, volumeMounts behavior on secret, configMap, downwardAPI and projected have changed to Read-Only by default.</p>

<p>A workaround to the problem is to create an emtpyDir volume and copy the contents into it and execute/write whatever you need.</p>

<p>this is a small snippet to demonstrate.</p>

<pre><code>    initContainers:
    - name: copy-ro-scripts
      image: busybox
      command: ['sh', '-c', 'cp /scripts/* /etc/pre-install/']
      volumeMounts:
        - name: scripts
          mountPath: /scripts
        - name: pre-install
          mountPath: /etc/pre-install
   volumes:
      - name: pre-install
        emptyDir: {}
      - name: scripts
        configMap:
          name: bla
</code></pre>

<p>Merged PR which causes this break :( 
<a href="https://github.com/kubernetes/kubernetes/pull/58720" rel="noreferrer">https://github.com/kubernetes/kubernetes/pull/58720</a></p>
