mpen
mpen

Reputation: 282915

Kubernetes overlay mounts and rsync

I'm trying to tweak my Kubernetes-based app to make it more development-friendly. I'm using kustomize to add some extra containers into my app-deployment. It looks like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-deployment
spec:
  template:
    spec:
      volumes:
        - name: php-src
          emptyDir: {}
        - name: nginx-src
          emptyDir: {}
        - name: webpack-src
          emptyDir: {}
      containers:
        - name: lsyncd
          image: axiom/rsync-server
          ports:
            - name: sshd
              containerPort: 22
            - name: rsyncd
              containerPort: 873
          env:
            - name: USERNAME
              value: user
            - name: PASSWORD
              value: pass
          volumeMounts:
            - name: php-src
              mountPath: /data/php
            - name: nginx-src
              mountPath: /data/nginx
            - name: webpack-src
              mountPath: /data/webpack
        - name: nginx
          volumeMounts:
            - name: nginx-src
              mountPath: /app
        - name: php
          volumeMounts:
            - name: php-src
              mountPath: /app
        - name: webpack
          image: dreg.mpen.ca/kymark/webpack
          imagePullPolicy: Never  # https://stackoverflow.com/a/54043058/65387
          ports:
            - name: http
              containerPort: 8082
          livenessProbe:
            httpGet:
              port: http
              path: /assets/manifest.json
            initialDelaySeconds: 20
            periodSeconds: 60
          command: ['node','--max_old_space_size=20000','node_modules/.bin/webpack-dev-server']
          volumeMounts:
            - name: webpack-src
              mountPath: /app

Basically, I've added a new rsync server with 3 volumes corresponding with the 3 different containers that I want to upload code to. This part is working great; I can rsync my code into the containers and it shows up instantly.

However, the nginx, PHP, and webpack images already have a bit of code in that /app directory (like node_modules and vendor). When I mount over the top of it, it disappears (which makes sense, since I'm mounting an emptyDir). But what I would like to do instead is use an overlay mount so that any code I upload will be 'overlayed' on top of what's already there.

Can I do that? How?

Upvotes: 2

Views: 3537

Answers (1)

pst
pst

Reputation: 1404

No, Kubernetes mounts, unlike Docker mounts do not allow mounting one directory over the other. Potential VOLUME lines from the Dockerfile do not matter.

A common solution for your use-case is, to use an init container to set up the emptyDir, before the main container is started. So basically you specify the emptyDir as a volume mount in both the init container and the main container and have the init container copy the files into the emptyDir.

Additionally, there are two projects that offer different solutions to what you are trying to achieve:

Using one of those you would not need the custom rsync and init container setup in your overlay.

Upvotes: 3

Related Questions