<p>As part of the PetSet definition, the volumeClainTemplates are defined for Kubernetes to dynamically generate Persistent Volume Claims. For example:</p>

<pre><code>  volumeClaimTemplates:
  - metadata:
      name: datadir
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 24Gi
</code></pre>

<p>However, I already has a few of the Persistent Volumes defined:</p>

<pre><code>#kubectl get pv    
NAME      CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                 REASON    AGE 
pv-1-rw   24Gi       RWO           Retain          Bound     rnd/pvc-1-rw             1h
pv-2-rw   24Gi       RWO           Retain          Bound     rnd/pvc-2-rw             6d
pv-3-rw   24Gi       RWO           Retain          Bound     rnd/pvc-3-rw             6d
...
</code></pre>

<p>I would like the Kubernetes to choose the persistent volumes from the existing ones rather than dynamically creating new ones. </p>

<p>I'm using Kubernetes 1.4.3. Does anyone know how to do that?</p>

<p><code>volumeClaimTemplates</code> is an array of <code>PersistentVolumeClaim</code>. You can try to define them using <code>selector</code> and label existing volumes somehow, i.e.:</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv0001
  labels:
    foo: foo
    bar: bar
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 5Gi
  hostPath:
    path: /data/pv0001/
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv0002
  labels:
    foo: foo
    bar: bar
spec:
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 5Gi
  hostPath:
    path: /data/pv0002/
---
kind: Service
apiVersion: v1
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
    - port: 80
  selector:
    app: nginx
---
kind: PetSet
apiVersion: apps/v1alpha1
metadata:
  name: nginx
spec:
  serviceName: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: gcr.io/google_containers/nginx-slim:0.8
          ports:
            - containerPort: 80
          volumeMounts:
            - name: html
              mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
    - metadata:
        name: html
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
        selector:
          matchLabels:
            foo: foo
            bar: bar
</code></pre>

<p>Of course, volumes must be available for bounding.</p>

<pre><code>$ kubectl get pvc html-nginx-0
NAME           STATUS    VOLUME    CAPACITY   ACCESSMODES   AGE
html-nginx-0   Bound     pv0002    5Gi        RWO           1m
$ kubectl get pv
NAME      CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS      CLAIM                  REASON    AGE
pv0001    5Gi        RWO           Retain          Available                                    2m
pv0002    5Gi        RWO           Retain          Bound       default/html-nginx-0             2m
</code></pre>
