Search code examples
dockerkubernetesdocker-volume

How to mount volumes on kubernetes using emptyDir


I am trying to create a deployment out of my kompose file, but whenever I try:

kompose convert -f docker-compose.yaml

I get the error:

Volume mount on the host "[file directory]" isn't supported - ignoring path on the host

I have tried a few different solutions to my issue, firstly trying to add hostPath to my kompose convert as well as using persistent volumes, however both do not work.

my kompose files looks like this:

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: {}

I am using kompose version 1.7.0

My Docker Compose version:

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

Solution

  • You need to take a look on warning you get:

    Volume mount on the host "[file directory]" isn't supported - ignoring path on the host
    

    It happens when volume in docker-compose.yaml is configured with direct path.

    Example below:

    version: '3'
    services:
      web:
        build: .
        ports:
          - "5000:5000"
        volumes:
          - "./storage1:/test1"
          - "./storage2:/test2"
      redis:
        image: "redis:alpine"
    volumes:
      storage1:
      storage2:
    
    

    Persistent Volume Claim

    Take a look on this link: Conversion matrix. It describes how kompose converts Docker's volumes to Kubernetes ones.

    Executing the conversion command without --volumes parameter:

    $ kompose convert -f docker-compose.yml

    With kompose 1.19 output will yield:

    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
    

    Warning message means that you are explicitly telling docker-compose to create volumes with direct path. By default kompose will convert Docker's volume to Persistent Volume Claim.

    emptyDir

    Executing the conversion command with --volumes emptyDir parameter:

    $ kompose convert -f docker-compose.yml --volumes emptyDir

    Will yield effect:

    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 will create emptyDir declaration inside web-deployment.yaml instead of creating separate definitions of PVC as it has in default.

    hostPath

    Executing the conversion command with --volumes hostPath parameter:

    $ kompose convert -f docker-compose.yml --volumes hostPath

    Will yield effect:

    INFO Kubernetes file "web-service.yaml" created   
    INFO Kubernetes file "redis-deployment.yaml" created 
    INFO Kubernetes file "web-deployment.yaml" created 
    

    As you can see there is no warning about not supported path. There is no warning because it created hostPath explicitly using your own provided paths from docker-compose.yml.

    Take a look on web-deployment.yaml volume section:

          volumes:
          - hostPath:
              path: /LOCAL_PATH-/POD_PATH/storage1
            name: web-hostpath0
          - hostPath:
              path: /LOCAL_PATH-/POD_PATH/storage2
            name: web-hostpath1