<p>I'm trying to create a PostgreSQL database in a Kubernetes cluster on Digital Ocean. To do so, I've created a <code>StatefulSet</code> and a <code>Service</code>. And to set up a volume in order to persist data, I took a look at the  <a href="https://docs.digitalocean.com/products/kubernetes/how-to/add-volumes/" rel="nofollow noreferrer">Add Block Storage Volumes tutorial</a>. My k8s configurations for the <code>StatefulSet</code> and <code>Service</code> are down below.</p>
<p>I simply used a <code>volumeClaimTemplates</code> . The storage class <code>do-block-storage</code> exists in the cluster (<code>volumeBindingMode</code> is set as <code>Immediate</code>). The <code>pv</code> and the <code>pvc</code> are successfully created.</p>
<blockquote>
<p>A volumeClaimTemplates that is responsible for locating the block storage volume by name csi-pvc. If a volume by that name does not exist, one will be created.</p>
</blockquote>
<p>But my pod falls in a <strong>CrashLoopBackOff.</strong> I'm getting:<code>0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims. Back-off restarting failed container</code></p>
<p>It is also worth saying that my cluster only has one node.</p>
<p>Can any please help me understand why? Thanks</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres-db
spec:
  serviceName: postgres-db
  selector:
    matchLabels:
      role: db
      app: my-app
  replicas: 1
  template:
    metadata:
      labels:
        role: db
        app: my-app
    spec:
      containers:
      - name: postgres
        image: postgres:13
        imagePullPolicy: &quot;IfNotPresent&quot;
        ports:
          - containerPort: 5432
        volumeMounts:
        - mountPath: &quot;/data&quot;
          name: csi-pvc
        - mountPath: &quot;/config&quot;
          name: postgres-config-map
      volumes:
        - name: postgres-config-map
          configMap:
            name: postgres-config
  volumeClaimTemplates:
  - metadata:
      name: csi-pvc
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      storageClassName: do-block-storage

---
apiVersion: v1
kind: Service
metadata:
  name: postgres-db
  labels:
    role: db
    app: my-app
spec:
  selector:
    role: db
    app: my-app
  ports:
  - port: 5432
    targetPort: 5432
  type: ClusterIP
</code></pre>
<p><a href="https://i.stack.imgur.com/oYZIE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oYZIE.png" alt="enter image description here" /></a></p>

Sofia
<p>I managed to fix my problem by adding the pvc first instead of using volumeClaimTemplates</p>
