Before posting this question I followed this answer How to mimic '--volumes-from' in Kubernetes but it didn't work for me.
I have 2 containers:
- node: its image contains all the files related to the app ( inside
/var/www
) - nginx: it needs to access the files inside the node image (especially the
/clientBuild
folder where I have all the assets)
What is inside the node image:
$ docker run node ls -l
> clientBuild/
> package.json
> ...
A part of the nginx.prod.conf
:
location ~* \.(jpeg|jpg|gif|png|ico|css|js|gz|map|json)$ {
include /etc/nginx/mime.types;
root /usr/local/nginx/html/clientBuild/;
}
And the the deployment setup:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: pwa-app-production
labels:
app: MyApp
spec:
replicas: 1
template:
metadata:
name: app
labels:
app: MyApp
env: production
spec:
containers:
- name: nginx
image: nginx
command: [nginx, -c, /nginx.prod.conf, -g, 'daemon off;']
resources:
limits:
memory: "500Mi"
cpu: "100m"
imagePullPolicy: Always
volumeMounts:
- mountPath: /usr/local/nginx/html
name: pwa-disk
readOnly: true
ports:
- name: nginx
containerPort: 80
initContainers:
- name: node
image: node
command: [npm, start]
resources:
limits:
memory: "500Mi"
cpu: "100m"
imagePullPolicy: Always
volumeMounts:
- mountPath: /var/www
name: pwa-disk
ports:
- name: app
containerPort: 3000
- name: api
containerPort: 3001
volumes:
- name: pwa-disk
emptyDir: {}
I first attempt to put both images in the same containers
key, but i got: /var/www/package.json not found
on npm start
Then I moved it inside the initContainers
but now I only have a notice that it failed, but it does not tell me why. View logs does not show any details too.
Notice that when I remove volume part, the npm start
works.