在發佈此問題之前,我遵循此答案How to mimic '--volumes-from' in Kubernetes,但它對我無效。Kubernetes在部署中的容器之間共享容量
我有2個集裝箱:
- 節點:它的形象包含了所有相關的應用程序(內部
/var/www
) - nginx的文件:它需要訪問節點裏面的文件圖片(尤其是
/clientBuild
文件夾,我擁有所有資產)
什麼是節點內圖像:
$ docker run node ls -l
> clientBuild/
> package.json
> ...
的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/;
}
而且安裝部署:
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: {}
我第一次嘗試將兩個圖像在同一containers
鍵,但我得到了:/var/www/package.json not found
對npm start
然後我把它移到initContainers
裏面,但是現在我只是注意到它失敗了,但它沒有告訴我爲什麼。查看日誌也不會顯示任何詳細信息。
請注意,當我刪除卷部分時,npm start
工作。
節點圖像是否已與生成的資產一起打包?或者,一旦容器在你的k8s集羣中的'npm start'啓動時它們就會生成? – fishi