6.3.7. 配置卷以在 pod 中用于多种用途

您可以使用 volumeMounts.subPath 属性来指定卷中的 subPath 而非卷的根目录,将卷配置为允许在一个 pod 中多处使用这个卷。

流程

  1. 运行 oc rsh 命令来查看卷中的文件列表:

    $ oc rsh <pod>

    输出示例

    sh-4.2$ ls /path/to/volume/subpath/mount
    example_file1 example_file2 example_file3

  2. 指定 subPath

    带有 subPath 参数的 Pod spec 示例

    apiVersion: v1
    kind: Pod
    metadata:
      name: my-site
    spec:
        containers:
        - name: mysql
          image: mysql
          volumeMounts:
          - mountPath: /var/lib/mysql
            name: site-data
            subPath: mysql 1
        - name: php
          image: php
          volumeMounts:
          - mountPath: /var/www/html
            name: site-data
            subPath: html 2
        volumes:
        - name: site-data
          persistentVolumeClaim:
            claimName: my-site-data

    1
    数据库存储在 mysql 文件夹中。
    2
    HTML 内容存储在 html 文件夹中。