首页 > 解决方案 > Kubernetes 存储类型 Hostpath- 文件映射问题

问题描述

您好我正在使用最新的 kubernetes 1.13.1 和 docker-ce(Docker 版本 18.06.1-ce,构建 e68fc7a)。

我设置了一个部署文件,该文件从主机(主机路径)挂载文件并将其挂载到容器中(挂载路径)。

该错误是当我尝试将查找从主机安装到容器时,我收到一条错误消息,指出它不是文件。(Kubernetes由于某种原因认为该文件是一个目录)

当我尝试使用以下命令运行容器时: Kubectl create -f 它永远停留在 ContainerCreating 阶段。

在使用 Kubectl describe pod 对其进行深入研究后,它会说:
是有一条错误消息,文件未被识别为文件。

这是部署文件:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: notixxxion
  name: notification
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: notification
    spec:
      containers:
      - image: docker-registry.xxxxxx.com/xxxxx/nxxxx:laxxt
        name: notixxxion
        ports:
        - containerPort: xxx0
####   host file configuration
        volumeMounts:
        - mountPath: /opt/notification/dist/hellow.txt
          name: test-volume
          readOnly: false
      volumes:
      - name: test-volume
        hostPath:
        # directory location on host
          path: /exec-ui/app-config/hellow.txt
        # this field is optional
          type: FileOrCreate
          #type: File
status: {}

标签: dockerkubernetes

解决方案


我已经重新安装了 kubernetes 集群,它变得更好了。kubernetes 现在可以毫无问题地读取文件并且容器在创建和运行中但是,主机路径存储类型还有一些其他问题:

包含挂载的 hostPath 不会更新,因为它们在主机上发生更改,即使我删除了 pod 并再次创建它


推荐阅读