2

I tried creating persistent volume using the host path. I can bind it to a specific node using node affinity but I didn't provide that. My persistent volume YAML looks like this

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins
  labels:
    type: fast
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /mnt/data

After this I created PVC

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 1Gi

And finally attached it onto the pod.

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: thinkingmonster/nettools
      volumeMounts:
        - mountPath: "/var/www/html"
          name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim

Now in describe command for pv or pvc it does not tell that on which node it has actually kept the volume /mnt/data

and I had to ssh to all nodes to locate the same.

And pod is smart enough to be created on that node only where Kubernetes had mapped host directory to PV

How can I know that on which node Kubernetes has created Persistent volume? Without the requirement to ssh the nodes or check that where is pod running.

Jonas
  • 121,568
  • 97
  • 310
  • 388
thinkingmonster
  • 5,063
  • 8
  • 35
  • 57

1 Answers1

2

It's only when a volume is bound to a claim that it's associated with a particular node. HostPath volumes are a bit different than the regular sort, making it a little less clear. When you get the volume claim, the annotations on it should give you a bunch of information, including what you're looking for. In particular, look for the:

volume.kubernetes.io/selected-node: ${NODE_NAME}

annotation on the PVC. You can see the annotations, along with the other computed configuration, by asking the Kubernetes api server for that info:

kubectl get pvc -o yaml -n ${NAMESPACE} ${PVC_NAME}
cassandracomar
  • 1,491
  • 7
  • 16
  • 2
    It's not showing.. in 1.18 :( may be removed as I don't think anyone uses host volumes in real production – thinkingmonster May 27 '20 at 05:20
  • Especially in cloud environments, it's common for nodes to be treated as disposable infrastructure too. You wouldn't store data in a host path on a specific node when it could be terminated without notice, and when you plan to replace it as part of a cluster upgrade. – David Maze May 27 '20 at 12:50