What is the VM folder when using Linux as OS and kvm as driver in kubernetes?

3/30/2017

The kubernetes docs provides for each OS and each driver the name VM when mounting a volume of type hostPath.

Nevertheless, it is missing that case:

  • OS: linux
  • Driver: kvm
  • Host folder: /home
  • VM folder: ???

This is the targeted deployment I would like to use in order to avoid to recreate the image after each change of the code.

This is only for the development env. In the production env, the code will be directly in the image.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: php-hostpath
spec:
  replicas: 1
  template:
    metadata:
  labels:
    app: php-hostpath
spec:
  containers:
  - name: php-hostpath
    image: php:7.0-apache
    ports:
    - containerPort: 80
    volumeMounts:
      - name: vol-php-hostpath
        mountPath: /var/www/html
  volumes:
  - name: vol-php-hostpath
    hostPath:
      path: /hosthome/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube/src/

Thanks...

-- Amine Jallouli
kubernetes
kvm
minikube

1 Answer

3/31/2017

Based on this doc, Host folder sharing is not implemented in the KVM driver yet. This is the driver I am using actually.

To overcome this, there are 2 solutions:

  • Use the virtualbox driver so that you can mount your hostPath volume by changing the path on you localhost /home/THE_USR/... to /hosthome/THE_USR/...

  • Mount your volume to the minikube VM based on the command $ minikube mount /home/THE_USR/.... The command will return you the path of your mounted volume on the minikube VM. Example is given down.

Example

(a) mounting a volume on the minikube VM

the minikube mount command returned that path /mount-9p

$ minikube mount -v 3 /home/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube
Mounting /home/amine/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube into /mount-9p on the minikubeVM
This daemon process needs to stay alive for the mount to still be accessible...
2017/03/31 06:42:27 connected
2017/03/31 06:42:27 >>> 192.168.42.241:34012 Tversion tag 65535 msize 8192 version '9P2000.L'
2017/03/31 06:42:27 <<< 192.168.42.241:34012 Rversion tag 65535 msize 8192 version '9P2000'

(b) Specification of the path on the deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: php-hostpath
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: php-hostpath
    spec:
      containers:
      - name: php-hostpath
        image: php:7.0-apache
        ports:
        - containerPort: 80
        volumeMounts:
          - name: vol-php-hostpath
            mountPath: /var/www/html
      volumes:
      - name: vol-php-hostpath
        hostPath:
          path: /mount-9p

(c) Checking if mounting the volume worked well

amine@amine-Inspiron-N5110:~/DockerProjects/gcloud-kubernetes/application/06-hostPath-volume-example-minikube$ kubectl exec -ti php-hostpath-3498998593-6mxsn bash
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php 
<?php
echo "This is my first docker project";
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php                                                                                                                                 
<?php

echo 'This is my first hostPath on kubernetes';
root@php-hostpath-3498998593-6mxsn:/var/www/html# cat index.php 
<?php

echo 'This is my first hostPath on kubernetes';
root@php-hostpath-3498998593-6mxsn:/var/www/html# 

NB: this kind of volume mounting is only development environment. If I were in production environment, the code will not be mounted: it will be in the image.

Hope it helps others.

-- Amine Jallouli
Source: StackOverflow