【问题标题】:hostPath as volume in kuberneteshostPath 作为 Kubernetes 中的卷
【发布时间】:2018-10-04 16:46:03
【问题描述】:

我正在尝试将 hostPath 配置为 Kubernetes 中的卷。我已经登录到 VM 服务器,我通常从那里使用 kubernetes 命令,例如 kubectl。

下面是 pod yaml:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: helloworldanilhostpath
spec:
  replicas: 1
  template:
    metadata:
      labels:
        run: helloworldanilhostpath
    spec:
      volumes:
        - name: task-pv-storage
          hostPath:
            path: /home/openapianil/samplePV
            type: Directory
      containers:
      - name: helloworldv1
        image: ***/helloworldv1:v1
        ports:
        - containerPort: 9123
        volumeMounts:
         - name: task-pv-storage
           mountPath: /mnt/sample

在 VM 服务器中,我创建了“/home/openapianil/samplePV”文件夹,其中有一个文件。它有一个 sample.txt 文件。

一旦我尝试创建此部署。它不会发生错误 -
警告 FailedMount 28s (x7 over 59s) kubelet, aks-nodepool1-39499429-1 MountVolume.SetUp failed for volume "task-pv-storage" : hostPath type check failed: /home/openapianil/samplePV is not a directory.

谁能帮我理解这里的问题。

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    hostPath 类型的卷是指 Pod 计划运行的节点(VM/机器)上的目录(在这种情况下为aks-nodepool1-39499429-1)。因此,您至少需要在该节点上创建此目录。

    为确保您的 Pod 始终安排在该特定节点上,您需要在 PodTemplate 中设置 spec.nodeSelector

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: helloworldanilhostpath
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            run: helloworldanilhostpath
        spec:
          nodeSelector:
            kubernetes.io/hostname: aks-nodepool1-39499429-1
          volumes:
            - name: task-pv-storage
              hostPath:
                path: /home/openapianil/samplePV
                type: Directory
          containers:
          - name: helloworldv1
            image: ***/helloworldv1:v1
            ports:
            - containerPort: 9123
            volumeMounts:
             - name: task-pv-storage
               mountPath: /mnt/sample
    

    在大多数情况下,使用这种类型的音量是个坏主意;有一些特殊的用例,但你的可能不是其中之一!

    如果您出于某种原因需要本地存储,那么更好的解决方案是使用local PersistentVolumes。

    【讨论】:

      猜你喜欢
      • 2019-12-01
      • 2019-09-11
      • 2018-01-09
      • 2021-06-09
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      相关资源
      最近更新 更多