Kubernetes: pod can't mount a PVC even though the latter seems to be properly bound to a PV
Usually you don't have to create PV first, when you create PVC, PV is created automatically. However, let's keep as it is and there is doubt about your storage class portainer-test
, how have you created it?
If you start from the beginning, I suppose you've created the secret for your API token to Hetzner and enabled CSI drivers, right? Then requesting PVC and deploying Pod
shouldn't be a problem, unless the driver type is supported by Kubernetes. I don't know what type you're having, but please note that Kubernetes supports for csi.hetzner.cloud
only v0.3, v1.0
versions.
Let's assume that you did everything correct before and the Kubernetes version (1.13 or newer) and driver versions are good.So then, here is the guide on how to manually create a PersistentVolume object to represent the existing volume:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-portainer-tes
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
csi:
driver: csi.hetzner.cloud
volumeHandle: portainer
readOnly: false
fsType: ext4
volumeAttributes:
foo: bar
controllerPublishSecretRef:
name: mysecret1
namespace: mynamespace
nodeStageSecretRef:
name: mysecret2
namespace: mynamespace
nodePublishSecretRef
name: mysecret3
namespace: mynamespace
Then attach and mount the volume by deploying a Pod
. When the pod referencing a CSI volume is scheduled, Kubernetes will trigger the appropriate operations against the external CSI plugin (ControllerPublishVolume, NodeStageVolume, NodePublishVolume, etc.) to ensure the specified volume is attached, mounted, and ready to use by the containers in the pod.
And note: there is a limit for csi drivers up to 16, please check if your limit is not almost 16
The problem was not related to k8s, but specific to Hetzner. In the project configuration I had left the volume attached to a fixed server, which obviously made it unavailable for attaching through the CSI driver. A user at the Hetzner Cloud forum pointed me to that.
I'd like to thank Bazhikov anyway as he gave me some hints that were useful in fixing other problems.