<p>I'm using <strong>gcsfuse</strong> to mount a volume in a container, and I need it to start my node.js application.</p>

<p>To mount the volume I'm using the <strong>lifecycle hooks of kubernetes</strong>, but it doesn't ensure that it will be executed before the entrypoint of my container.</p>

<p>I've been thinking about how should I check when the volume is mounted, and if it goes down.</p>

<p>To check when it is mounted and unmounted I read and search the existence of the volume in <code>/proc/mounts</code>, and adding a watcher to it for changes.</p>

<p>Is there a simplier way to ensure that the volume is mounted in node.js, docker, or kubernetes?</p>

<p>You can run this dockerfile in privileged mode:</p>

<pre><code>FROM ubuntu 
RUN echo "deb http://packages.cloud.google.com/apt gcsfuse-stretch main" | tee /etc/apt/sources.list.d/gcsfuse.list 
RUN apt-get update &amp;&amp; apt install curl -y 
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 
RUN apt-get update 
RUN apt-get install gcsfuse fuse -y 
RUN mkdir -p /mnt/tmp 
CMD gcsfuse [BUCKET NAME] /mnt/tmp &amp;&amp; /bin/bash
</code></pre>

<p>This way you are sure that the bucket is mounted when the pod initializes.</p>

<p>On the other hand I do not recommend this approach as there is a Node.sj library for Google Cloud Storage [1].</p>

<p>Here is an example of bucket listing:</p>

<pre><code>// Imports the Google Cloud client library
const Storage = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

// Lists all buckets in the current project
storage
  .getBuckets()
  .then(results =&gt; {
    const buckets = results[0];

    console.log('Buckets:');
    buckets.forEach(bucket =&gt; {
      console.log(bucket.name);
    });
  })
  .catch(err =&gt; {
    console.error('ERROR:', err);
  });
</code></pre>

<p>[1] <a href="https://github.com/googleapis/nodejs-storage/tree/master/samples" rel="nofollow noreferrer">https://github.com/googleapis/nodejs-storage/tree/master/samples</a></p>
