我试图用我的kompose文件创建一个部署,但是每当尝试尝试时:
kompose convert -f docker-compose.yaml
我得到错误:
Volume mount on the host "[file directory]" isn't supported - ignoring path on the host
我已经尝试了几种不同的解决方案来解决这个问题,首先尝试将
hostPath
添加到我的kompose convert
中,以及使用持久卷,但是这两种方法都不起作用。我的kompose文件看起来像这样:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yaml --volumes emptyDir
kompose.version: 1.7.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: es01
name: es01
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: es01
spec:
containers:
- env:
- name: COMPOSE_CONVERT_WINDOWS_PATHS
value: "1"
- name: COMPOSE_PROJECT_NAME
value: elastic_search_container
- name: ES_JAVA_OPTS
value: -Xms7g -Xmx7g
- name: discovery.type
value: single-node
- name: node.name
value: es01
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.1
name: es01
ports:
- containerPort: 9200
resources: {}
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: es01-empty0
restartPolicy: Always
volumes:
- emptyDir: {}
name: es01-empty0
status: {}
我正在使用kompose版本1.7.0
我的Docker Compose版本:
version: '3'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.1
container_name: es01
environment:
- node.name=es01
- COMPOSE_PROJECT_NAME=elastic_search_container
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms7g -Xmx7g"
- COMPOSE_CONVERT_WINDOWS_PATHS=1
ulimits:
nproc: 3000
nofile: 65536
memlock: -1
volumes:
- /home/centos/Sprint0Demo/Servers/elasticsearch:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- kafka_demo
最佳答案
您需要看一下警告您得到:
Volume mount on the host "[file directory]" isn't supported - ignoring path on the host
当
docker-compose.yaml
中的卷配置有直接路径时,会发生这种情况。下面的例子:
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- "./storage1:/test1"
- "./storage2:/test2"
redis:
image: "redis:alpine"
volumes:
storage1:
storage2:
持续体积 claim
看一下此链接:Conversion matrix。
它描述了
kompose
如何将Docker的卷转换为Kubernetes的卷。在不使用
--volumes
参数的情况下执行转换命令:$ kompose convert -f docker-compose.yml
使用
kompose
1.19输出将产生:WARN Volume mount on the host "SOME_PATH" isn't supported - ignoring path on the host
WARN Volume mount on the host "SOME_PATH" isn't supported - ignoring path on the host
INFO Kubernetes file "web-service.yaml" created
INFO Kubernetes file "redis-deployment.yaml" created
INFO Kubernetes file "web-deployment.yaml" created
INFO Kubernetes file "web-claim0-persistentvolumeclaim.yaml" created
INFO Kubernetes file "web-claim1-persistentvolumeclaim.yaml" created
警告消息表示您正在明确告诉
docker-compose
创建具有直接路径的卷。默认情况下,kompose
将Docker的卷转换为Persistent Volume Claim。空目录
使用
--volumes emptyDir
参数执行转换命令:$ kompose convert -f docker-compose.yml --volumes emptyDir
会产生效果:
WARN Volume mount on the host "SOME_PATH" isn't supported - ignoring path on the host
WARN Volume mount on the host "SOME_PATH" isn't supported - ignoring path on the host
INFO Kubernetes file "web-service.yaml" created
INFO Kubernetes file "redis-deployment.yaml" created
INFO Kubernetes file "web-deployment.yaml" created
kompose
将在web-deployment.yaml内创建emptyDir声明,而不是像默认情况下那样创建单独的PVC定义。hostPath
使用
--volumes hostPath
参数执行转换命令:$ kompose convert -f docker-compose.yml --volumes hostPath
会产生效果:
INFO Kubernetes file "web-service.yaml" created
INFO Kubernetes file "redis-deployment.yaml" created
INFO Kubernetes file "web-deployment.yaml" created
如您所见,没有关于不支持的路径的警告。没有警告,因为它使用您自己提供的
docker-compose.yml
路径显式创建了hostPath。看一看
web-deployment.yaml
卷部分: volumes:
- hostPath:
path: /LOCAL_PATH-/POD_PATH/storage1
name: web-hostpath0
- hostPath:
path: /LOCAL_PATH-/POD_PATH/storage2
name: web-hostpath1