Kubernetes存储类型主机路径-文件映射问题

时间:2019-01-08 19:17:54

标签: docker kubernetes

嗨,我正在使用最新的kubernetes 1.13.1和docker-ce(Docker版本18.06.1-ce,内部版本e68fc7a)。

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

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

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

在使用Kubectl对其进行更深入的描述后,将其描述为:
是一个错误消息,该文件未被识别为文件。

这是部署文件:

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: {}

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

检查您要挂载的文件权限!

作为最后的尝试,请尝试使用特权模式。

希望有帮助!