Reputation: 423
My app pod and nginx pod share a persistent volume for static files. When the app image is built with docker, the static files are generated in the location that the static persistent volume will later bind to when the containers are deployed.
However it seems that during the deployment all the files are wiped off the static directory. Does this have to do with the order of the deployment? Ex: the persistent volume has to be applied first, then the nginx deployment (because the static mounted directory is blank at first), then the app (which already has files in the mounted directory)
Upvotes: 4
Views: 3590
Reputation: 74680
Kubernetes (really the container runtime underneath) bind mounts a volume/directory from the host into the container. All files and sub directories in the containers target directory are hidden under the contents of the directory that is now mounted on top.
Do you really need a shared volume for this data? Is any of it being updated at runtime?
If you do need the shared data, you could add an initContainer
to your deployment and it can manage the copy of data to the volume. For complex scenarios, rsync
will usually have a flag for what you need to do.
initContainers:
- name: app
image: my/nginx:1.17
volumeMounts:
- name: app-data
mountPath: /app/data
- name: app-data
image: my/app:3.1.4
command: ["sh", "-c", "cp -r /app/dist/. /app/data"]
volumeMounts:
- name: app-data
mountPath: /app/data
It sounds like you are hosting an SPA. If the shared volume is simply to get the static built files into the nginx container, maybe inject the files into web server container at build rather than dealing with volumes.
FROM docker.io/node:12 AS build
WORKDIR /app
COPY . /app/
RUN yarn install && yarn build
FROM docker.io/nginx:1.17
COPY --from=build /app/dist/. /usr/share/nginx/html/
CMD [ "nginx", "-g", "daemon off;" ]
Upvotes: 2