<p>I am an newbie for Kubernetes and Cloudrun deployment using YAML file, So pardon if this question should very basic.</p>
<p><strong>Problem</strong>: I have files that are stored in cloud storage. I want to download these files in the local mount before the container spins up my docker entrypoint.</p>
<blockquote>
<p>It is my understanding that KNative does not support volumes or
persistentVolumeClaims.</p>
</blockquote>
<p>Please correct me if this understanding is wrong.</p>
<p>Let me explain it better using an image below,
<a href="https://i.stack.imgur.com/1KXgS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1KXgS.png" alt="enter image description here" /></a></p>
<p>Inside the Kubernetes pod, I have divided the container startup into 3 section.</p>
<ol>
<li>Prehook to download files from GCS (Google Cloud Storage) -&gt; This will copy files from google storage to local mount. Possible using some kind of init container with cloudsdk image and then gsutils to copy the files down.</li>
<li>Local Mount Filesystem -&gt; The prehook will write into this mount. The container having the &quot;container Image&quot; will also have access to this mount.</li>
<li>container Image -&gt; This is my main container image running in the container.</li>
</ol>
<p>I am looking for Knative serving solution that will work on cloudrun. How do I solve this?</p>
<p>Additional, is it possible to have yaml file without Knative serving for creating an cloudrun service?</p>

<p>Knative contract, as you said, doesn't allow to mount or claim a volume. So, you can't achieve this (for now, on Cloud Run managed).</p>
<p>On the other hand, Pod allow this, but Knative is a special version of &quot;Pod&quot;: no persistent volume, and you can't define a list of container, it's a pod with only one container (+ the mesh (most of the time Istio) sidecar injected when you deploy)</p>
<p>For you additional question, Cloud Run implements Knative API. And thus, you need to present Knative serving YAML file to configure your service.</p>
<hr />
<p>If you want to write file, you can do it in the <code>/tmp</code> in memory partition. So, at your container starts, download the file and store them there. However, if you update the files and you need to push the update, you need to push them manually to Cloud Storage.</p>
<p>In addition, the other running instances, that have already downloaded the file and stored them in their <code>/tmp</code> directory won't see the file change in Cloud Storage; it's only the new instances.</p>
<p>UPDATE 1:</p>
<p>If you want to download the files &quot;before&quot; the container start, you have 2 solutions:</p>
<ol>
<li>&quot;Before&quot; is not possible, you can do this at startup:</li>
</ol>
<ul>
<li>The container start</li>
<li>Download the files, initiate what you need</li>
<li>Serve traffic with your webserver.</li>
</ul>
<p>The previous solution has 2 issues</p>
<ul>
<li>The service cold start is impacted by the download before serving</li>
<li>The max size of file is limited by the max memory size of the instance (<code>/tmp</code> directory is an in-memory file system. If you have a config of 2Gb, the size is max 2Gb minus the memory footprint of your app)</li>
</ul>
<ol start="2">
<li>The second solution is to build your container with the file already present in the container image.</li>
</ol>
<ul>
<li>No cold start impact</li>
<li>No memory limitation</li>
<li>Reduce your agility and you need to build and deploy a new revision with a file change.</li>
</ul>
<p>UPDATE 2:</p>
<p>For the solution1, it's not a Knative solution, it's in your code! I don't know your language and framework, but at startup, you need to use Google Cloud Storage client library to download, from your code, the file that you need.</p>
<p><em>Show me your server startup I could try to provide you an example!</em></p>
<p>For the solution 2, the files aren't in your git repo, but still in your Cloud Storage. Your Docker file can look like to this</p>
<pre><code>FROM google/cloud-sdk:alpine as gcloud
WORKDIR /app

# IF you aren't building your image on Cloud Build, you need to be authenticated
#ARG KEY_FILE_CONTENT
#RUN echo $KEY_FILE_CONTENT | gcloud auth activate-service-account --key-file=- &amp;&amp; \

# Get the file(s)
gsutil cp gs://my-bucket/name.csv .

FROM golang:1.15-buster as builder

WORKDIR /app
COPY go.* ./
....
RUN go build -v -o server

FROM debian:buster-slim

# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/server /app/server
COPY --from=gcloud /app/name.csv /app/name.csv

# Run the web service on container startup.
CMD [&quot;/app/server&quot;]
</code></pre>
<p>You can also imagine downloading the file before the Docker build command and simply perform a copy in the Dockerfile. I don't know your container creation pipeline, but it's ideas that you can reuse!</p>
