ehough / docker-nfs-server

A lightweight, robust, flexible, and containerized NFS server.
https://hub.docker.com/r/erichough/nfs-server/
GNU General Public License v3.0
669 stars 221 forks source link

[Suggestion/PR] Support readiness flag for exports volume #55

Closed Tristan971 closed 3 years ago

Tristan971 commented 3 years ago

Hello, thanks for this project first,

I plan to use it on a kubernetes cluster to share a volume (obviously) across pods, and ran into a small issue that might be addressable.

Situation

Here's the layout of the containers I want to run on a given host

host
    containers:
        - exports-filler
            - /data ----------------
        - nfs-server                |
            - /etc/exports ---------
    volumes:                        |
        - data  --------------------

The problem

I want the exports-filler container to start and finish initializing itself (successfully) before the nfs-server starts (or at least boots up the whole exports setup)

Turns out k8s doesn't have a feature to order containers within a pod (I know, I also assumed it would support this),

So I can't say "start exports-filler, wait for it to be up, then start nfs-server"

(N.B.: initContainers don't cut it in this case because exports-filler won't/mustn't complete, as it syncs with an upstream provider all the time)

Workaround

I made a quick workaround here for now, which involves:

Sample (naive) implementation here: https://github.com/ehough/docker-nfs-server/compare/develop...Tristan971:support-awaiting-for-exports-readiness?expand=1

First, is it something you might want to support in this? And if so, any idea of nicer ways to go about it? (I'm totally ok with doing the implementation, for what it's worth)

Thanks

ehough commented 3 years ago

Thanks for your detailed question! That's a tricky situation, but your workaround seems like a good solution to me. You could even simplify it a bit, perhaps, by simply overriding this image's entrypoint. I'm not a k8s expert but I think it would look something like this:

spec:
  containers:
  - name: nfs-server
    image: erichough/nfs-server
    ...
    command:
      - /bin/bash
      - -c
      - 'while [[ ! -f /nfs/.ready ]]; do sleep 5; done; exec /usr/local/bin/entrypoint.sh

That way, there'd be no need to extend/fork this image. Thoughts?

In the spirit of keeping this image as lean as possible, I'm going to decline incorporating this type functionality into the base image (for now, anyway). Closing this issue but let's keep the discussion going, if you'd like.

Tristan971 commented 3 years ago

Hi, I feel a bit silly not doing that from the get go now!

Thanks for reply and agreed on keeping the image lean! 👍