使用Linux作为操作系统和kvm作为kubernetes中的驱动程序时,VM文件夹是什么?

时间:2017-03-30 19:50:54

标签: kubernetes kvm minikube

在安装 hostPath 类型的卷时,kubernetes docs为每个操作系统和每个驱动程序提供名称VM。

然而,缺少这种情况:

  • OS:linux
  • 司机:kvm
  • 主机文件夹:/ home
  • VM文件夹:???

这是我想要使用的目标部署,以避免在每次更改代码后重新创建图像。

这仅适用于开发环境。在生产环境中,代码将直接在图像中。

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/

...谢谢

1 个答案:

答案 0 :(得分:2)

基于此doc,尚未在KVM驱动程序中实现主机文件夹共享。这是我实际使用的驱动程序。

为了克服这个问题,有两种解决方案:

  • 使用 virtualbox 驱动程序,以便通过将localhost /home/THE_USR/...上的路径更改为/hosthome/THE_USR/...

  • 根据命令$ minikube mount /home/THE_USR/...将卷装入minikube VM。该命令将返回minikube VM上已安装卷的路径。示例给出了。

实施例

(a)在minikube VM上安装卷

minikube mount命令返回路径/ 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)部署路径的规范

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)检查安装音量是否正常工作

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:这种卷安装只是开发环境。如果我在生产环境中,则不会安装代码:它将在图像中。

希望它可以帮助他人。