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

但是,缺少这种情况:

  • 操作系统: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/
    

    谢谢...

    最佳答案

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

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

  • 使用虚拟框驱动程序,以便通过将localhost /home/THE_USR/...上的路径更改为/hosthome/THE_USR/...
  • 来挂载hostPath卷
  • 根据命令$ 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#
    

    注意:这种卷安装只是开发环境。如果我在生产环境中,则不会挂载代码:它将在镜像中。

    希望它能帮助别人。

    关于kubernetes - 在kubernetes中将Linux用作OS并将kvm用作驱动程序时,VM文件夹是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43127127/

    10-16 16:26