简体   繁体   中英

Kubernetes Persistent Volume Mount not found

I am trying to create and mount a volume but getting stuck.

This part creates the storage:

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

The following is a continuation of my deployment section:

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


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

I keep getting the below error message:

The Deployment "traefik-ingress-controller" is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: "config"

Any help is appreciated.

UPDATE:

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

Looks like you have an indentation it's finding the VolumeMount but not the Volume. Something like this should work:

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

Let's debug:

1) the name of your PersistentVolumeClaim is pvclaim2 and everything looks ok

2) VolumeMounts section looks ok. config is in read-only mode and it is correct for config.

3) volumes section describes that config volume's type is the persistentVolumeClaim and it links to the PVC pvclaim2 - ok!

4) Next we can see that config volume's type is the configMap along with the PersistentVolumeClaim at the same time...and that will be the reason of an errors in the future. Assuming you wanted to use config volume as a mount for configfile traefik.toml you don't need PVC (especially 5 gigabytes in read-only mode)

All you need to do is create configMap . Command syntax:

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

In your case it could be done like this:

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

Then you need to update your Deployment:

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

Im going to take a wild guess here, is your traefik ingress controller running in the same namespace as your pvc? Pvc are namespace scoped, in your example, it is in default namespace. Normally we deploy ingress into its own namespace like "ingress" and its other associated pods.

This is because there is no PersistentVolume(PV) to be bound to that PersistentVolumeClaim(PVC). This can be due to several reasons.

One thing is you haven't created a PV for the claim. A PVC need to have a PV to be claimed. If that so first you need to create a Persistance volume of any type of multiple types supported by kubernets. An example of PV using a nfs can be found here .

The second reason may be that any parameter of any of the existing and unbound PV is not matched with PVC. So check whether the storage capacity, access modes, storage class and labels of PV and PVC are matched. As an example if you want your PVC of the storageClassName: managed-premium make sure that your PV also have the storage Class Type.

And the last thing may be the PV that you think there is and match all parameters with PVC bound to some other PVC. PV is an atomic abstraction and you cannot use one PV for multiple PVCs.

You can use kubectl get pv to check whether there are volumes which has STATUS available and matching the PVCs requirements.

I've also encountered this error. Be sure that the PVC are pointing to the correct namespace, since PVCs are namespaced. PV aren't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM