4.8. 使用 hostPath 的持久性存储

OpenShift Container Platform 集群中的 hostPath 卷将主机节点的文件系统中的文件或目录挂载到 pod 中。大多数 pod 都不需要 hostPath 卷,但是如果应用程序需要它,它会提供一个快速的测试选项。

重要

集群管理员必须将 pod 配置为以特权方式运行。这样可访问同一节点上的 pod。

4.8.1. 概述

OpenShift Container Platform 支持在单节点集群中使用 hostPath 挂载用于开发和测试目的。

在用于生产环境的集群中,不要使用 hostPath。集群管理员会置备网络资源,如 GCE Persistent Disk 卷、NFS 共享或 Amazon EBS 卷。网络资源支持使用存储类设置动态置备。

hostPath 卷必须静态置备 。

重要

不要挂载到容器 root、/ 或主机和容器中相同的任何路径。如果容器有足够权限,可能会损坏您的主机系统。使用 /host 挂载主机是安全的。以下示例显示主机中的 / 目录被挂载到位于 /host 的容器中。

apiVersion: v1
kind: Pod
metadata:
  name: test-host-mount
spec:
  containers:
  - image: registry.access.redhat.com/ubi8/ubi
    name: test-container
    command: ['sh', '-c', 'sleep 3600']
    volumeMounts:
    - mountPath: /host
      name: host-slash
  volumes:
   - name: host-slash
     hostPath:
       path: /
       type: ''