# 卷 "my-volume" 的 MountVolume.SetUp 失败：hostPath 类型检查失败：/data/logs 不是一个目录

- **ID:** `kubernetes/volume-mount-failed-hostpath-type-mismatch`
- **领域:** kubernetes
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

hostPath 卷的类型设置为 'Directory'，但节点上指定的路径是一个文件或不存在。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kubernetes v1.27.0 | active | — | — |
| Kubernetes v1.28.0 | active | — | — |
| Kubernetes v1.30.0 | active | — | — |

## 解决方案

1. ```
   SSH 到节点并创建目录：`ssh node-user@node-ip 'sudo mkdir -p /data/logs'`。
   ```
2. ```
   如果路径是一个文件，将 Pod spec 改为使用 `type: FileOrCreate` 或完全移除 type 字段。
   ```
3. ```
   使用 `ls -la /data/logs` 检查节点上的路径以验证其类型，然后相应调整 Pod YAML。
   ```

## 无效尝试

- **Changing the pod's restart policy to Always** — The pod will keep restarting but still fail because the underlying path issue persists. (100% 失败率)
- **Adding a PVC instead of hostPath without understanding the requirement** — PVCs require storage classes and may not match the need for node-local storage. (60% 失败率)
