title: Pod affinity to host node of bound local persistent volume
body: <p>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 <a href="https://github.com/zalando/postgres-operator" rel="nofollow noreferrer">postgres-operator</a>.  Since I'm on bare metal, I cannot make use of dynamic PVCs, as seems to be normal in the tutorials.</p>
  
  <p>To begin with, I created some PVs bound to manually created volumes on the host nodes. The PVs are assigned, using <code>nodeAffinity</code>, to specific nodes.  i.e. <code>primary-vol</code> PV is assigned to <code>node1</code>, and <code>replica-vol-1</code> is assigned to <code>node2</code> and so on. </p>
  
  <p>I am then binding my pod to the PV using a PVC as documented <a href="https://kubernetes.io/blog/2019/04/04/kubernetes-1.14-local-persistent-volumes-ga/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>What I've found is that the k8s scheduler has placed my pod (which is bound to a PV on <code>node1</code>) on <code>node2</code> rather than <code>node1</code> as I expected.</p>
  
  <p>Is there a way, using affinity on the pod, to ensure that the pod is created on the <strong>same node</strong> as the PV it is bound to?</p>
  
  <p><strong>EDIT</strong>: to simplify the question (<em>with apologies to artists and architects everywhere</em>)</p>
  
  <p>How can the pod know what node the PV is assigned to, when it doesn't even know what PV it is bound to?</p>
  
  <p><a href="https://i.stack.imgur.com/WQbT9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WQbT9.png" alt="How can the pod know what node the PV is assigned to, when it doesn&#39;t even know what PV it is bound to?"></a></p>