I'm working on a bare-metal inst of k8s, and am trying out local persistent volume using k8s v1.14. The purpose is to allow me to create an HA postgres deployment using postgres-operator. Since I'm on bare metal, I cannot make use of dynamic PVCs, as seems to be normal in the tutorials.
To begin with, I created some PVs bound to manually created volumes on the host nodes. The PVs are assigned, using nodeAffinity
, to specific nodes. i.e. primary-vol
PV is assigned to node1
, and replica-vol-1
is assigned to node2
and so on.
I am then binding my pod to the PV using a PVC as documented here.
What I've found is that the k8s scheduler has placed my pod (which is bound to a PV on node1
) on node2
rather than node1
as I expected.
Is there a way, using affinity on the pod, to ensure that the pod is created on the same node as the PV it is bound to?
EDIT: to simplify the question (with apologies to artists and architects everywhere)
How can the pod know what node the PV is assigned to, when it doesn't even know what PV it is bound to?