<p>I have a quick question regarding kubernetes yaml files :</p>

<p>can I reference a node label value in a pvc, using a node label as variable?</p>

<p>Something like :</p>

<pre><code>  volumes:
    - name: data-storage
      persistentVolumeClaim:
        claimName: main-dev-pvc-${node.failure-domain.beta.kubernetes.io/zone}
</code></pre>

<p>Is it possible?</p>

Guillaume
<p>Is the idea to force the use of PV created in a specific zone? <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="nofollow noreferrer">StorageClass</a> can help with that.</p>

<p>Custom StorageClass:</p>

<pre><code>apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ssd-usc1a
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
  zones: us-central1-a
</code></pre>

<p>PVC that refers to the custom storage class:</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: main-dev-pvc-ssd-usc1a
  namespace: dev-project
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: ssd-usc1a
</code></pre>

<p>Assuming the same namespace as for the PVC:</p>

<pre><code>  volumes:
    - name: data-storage
      persistentVolumeClaim:
        claimName: main-dev-pvc-ssd-usc1a
</code></pre>

<p>Kubernetes will try to schedule the pod on a node in the same zone where the PV is (us-central1-a in the example above). Quote from the docs: "...The scheduler (via the VolumeZonePredicate predicate) will also ensure that pods that claim a given volume are only placed into the same zone as that volume, as volumes cannot be attached across zones". Therefore, the scheduling will fail if there isn't a such suitable node.</p>
