Reputation: 535
I'm trying to create a PostgreSQL database in a Kubernetes cluster on Digital Ocean. To do so, I've created a StatefulSet
and a Service
. And to set up a volume in order to persist data, I took a look at the Add Block Storage Volumes tutorial. My k8s configurations for the StatefulSet
and Service
are down below.
I simply used a volumeClaimTemplates
. The storage class do-block-storage
exists in the cluster (volumeBindingMode
is set as Immediate
). The pv
and the pvc
are successfully created.
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.
But my pod falls in a CrashLoopBackOff. I'm getting:0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims. Back-off restarting failed container
It is also worth saying that my cluster only has one node.
Can any please help me understand why? Thanks
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: "IfNotPresent"
ports:
- containerPort: 5432
volumeMounts:
- mountPath: "/data"
name: csi-pvc
- mountPath: "/config"
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
Upvotes: 1
Views: 480
Reputation: 535
I managed to fix my problem by adding the pvc first instead of using volumeClaimTemplates
Upvotes: 2