当我试图挂载hostPath卷时,我对Kubernetes的卷有一个问题。(我也尝试过使用PVC,但没有成功)
Dockerfile:
FROM node:16
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN yarn install
COPY . /usr/src/app
EXPOSE 3000
ENTRYPOINT ["yarn", "start:dev"]docker-compose.yml:
version: '3.8'
services:
api:
container_name: api
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 3000:3000
restart: always
labels:
kompose.volume.type: 'hostPath'
database:
container_name: database
image: postgres:latest
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: task-managementapi-development.yml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose -f docker-compose.yml convert
kompose.version: 1.26.1 (HEAD)
kompose.volume.type: hostPath
creationTimestamp: null
labels:
io.kompose.service: api
name: api
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: api
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose -f docker-compose.yml convert
kompose.version: 1.26.1 (HEAD)
kompose.volume.type: hostPath
creationTimestamp: null
labels:
io.kompose.service: api
spec:
containers:
- image: task-management_api
name: api
imagePullPolicy: Never
ports:
- containerPort: 3000
resources: {}
volumeMounts:
- mountPath: /usr/src/app
name: api-hostpath0
- mountPath: /usr/src/app/node_modules
name: api-hostpath1
restartPolicy: Always
volumes:
- hostPath:
path: /Users/handrei/workspace/devs/nest-ws/task-management
name: api-hostpath0
- hostPath:
name: api-hostpath1
status: {}我从吊舱收到的错误是下一个错误:
kubectl日志api-84b56776c5-v86c7
yarn run v1.22.17
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Couldn't find a package.json file in "/usr/src/app"我认为卷是有问题的,因为应用没有卷的部署和服务是可行的
发布于 2022-03-10 07:51:52
hostPath卷将文件或目录从主机节点的文件系统挂载到Pod中。
对于所需的path属性,还可以为hostPath卷指定一个hostPath。
注意到:HostPath卷带来了许多安全风险,在可能的情况下避免使用HostPaths是最佳实践。当必须使用HostPath卷时,它的作用域应该仅限于所需的文件或目录,并作为ReadOnly挂载。
正如@戴维·麦子之前提到的,最好是
在Kubernetes中,在本地使用Node进行日常开发,并使用一个独立的映像(根本没有任何卷挂载)。(...)
node_modules目录是空的,在Kubernetes中没有任何东西会在那里复制数据。您需要删除部署规范中的所有卷声明才能运行。
这句话将帮助您将Docker转换为Kubernetes参考资料。
还请参阅StackOverflow上的以下问题:
https://stackoverflow.com/questions/71372404
复制相似问题