找不到Kubernetes持久卷安装

时间:2018-12-20 19:03:19

标签: kubernetes azure-kubernetes

我正在尝试创建和安装卷,但是卡住了。

这部分创建存储:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvclaim2
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: managed-premium
  resources:
    requests:
      storage: 5Gi

以下是我的部署部分的延续:

volumeMounts:
- name: config
  mountPath: /config
  readOnly: true
args:
- --configfile=/config/traefik.toml


volumes:
  - name: config
    persistentVolumeClaim:
      claimName: pvclaim2
    configMap:
    name: traefik-config

我不断收到以下错误消息:

  

部署“ traefik-ingress-controller”无效:   spec.template.spec.containers [0] .volumeMounts [0] .name:找不到:   “配置”

感谢您的帮助。

更新:

Output from describe pv:

Conditions:
  Type           Status
  PodScheduled   False
Volumes:
  certs:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  pvclaim101
    ReadOnly:   false
  config:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      traefik-conf
    Optional:  false
  traefik-ingress-controller-token-6npxp:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  traefik-ingress-controller-token-6npxp
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age               From               Message
  ----     ------            ----              ----               -------
  Warning  FailedScheduling  1m (x25 over 2m)  default-scheduler  persistentvolumeclaim "pvclaim101" not found

4 个答案:

答案 0 :(得分:2)

好像您有一个缩进,它找到的是VolumeMount,而不是Volume。这样的事情应该起作用:

containers:
- image: your-image
  name: your-containers
  volumeMounts:
  - name: config
    mountPath: /config
    readOnly: true
  args:
  - --configfile=/config/traefik.toml
volumes:
  - name: config
    persistentVolumeClaim:
      claimName: pvclaim2
    configMap:
    name: traefik-config

答案 1 :(得分:1)

让我们调试:

1)您的PersistentVolumeClaim的名称为pvclaim2,一切正常。

2)VolumeMounts部分看起来不错。 config处于只读模式,它对于配置是正确的。

3)volumes部分描述了config卷的类型为persistentVolumeClaim,它链接到PVC pvclaim2-好的!

4)接下来,我们可以看到config卷的类型是configMapPersistentVolumeClaim同时...这将是导致错误的原因。未来。假设您想使用config卷作为配置文件traefik.toml的挂载,则不需要PVC(尤其是在只读模式下为5 GB)

您需要做的就是创建configMap。命令语法:

kubectl create configmap <map-name> <data-source>

在您的情况下,可以这样进行:

kubectl create configmap traefik-config --from-file=<your-local-path-to-file>/traefik.toml

然后您需要更新您的部署:

containers:
- image: your-image
  name: your-containers
  volumeMounts:
  - name: config
    mountPath: /config
    readOnly: true # as far as i know configmaps are read-only since 1.9.5
  - name: some-persistent-storage-name
    mountPath: /<some-mount-point-for-storage>

...

volumes:
  - name: config
    configMap:
      name: traefik-config
  - name: some-persistent-storage-name
    persistentVolumeClaim:
      claimName: pvclaim2

答案 2 :(得分:1)

我要在这里进行一个疯狂的猜测,您的traefik入口控制器是否在与pvc相同的名称空间中运行? Pvc是命名空间范围的,在您的示例中,它是在默认命名空间中。通常,我们会将入口部署到它自己的名称空间(例如“入口”和其他关联的Pod)中。

答案 3 :(得分:0)

这是因为没有PersistentVolume(PV)绑定到该PersistentVolumeClaim(PVC)。这可能是由于多种原因。

一件事是您尚未为索赔创建PV。 PVC需要具有PV才能声明。如果是这样,首先需要创建一个由Kubernets支持的任何类型的多个types的Persistance卷。可以在here中找到使用nfs的PV的示例。

第二个原因可能是任何现有的和未绑定的PV的任何参数都与PVC不匹配。因此,请检查PV和PVC的存储容量,访问方式,存储类别和标签是否匹配。例如,如果您想要storageClassName: managed-premium的PVC,请确保您的PV也具有存储类类型。

最后一件事可能是您认为存在的PV,并将所有参数与绑定到其他PVC的PVC匹配。 PV是一种原子抽象,不能将一个PV用于多个PVC。

您可以使用kubectl get pv检查是否有具有STATUS可用且符合PVC要求的卷。

相关问题