I'm trying to deploy a postgres service to google cloud kubernetes with a persistent volume and persistent volume claim to provide storage for my application.
When I deploy, the pod gets stuck in a CrashLoopBackOff
.
One of the pod's events fails with the message:
Error: failed to start container "postgres": Error response from daemon: error while creating mount source path '/data/postgres-pv': mkdir /data: read-only file system
This is the yaml I am trying to deploy using kubectl:
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv
labels:
type: local
app: postgres
spec:
capacity:
storage: 5Gi
storageClassName: standard
accessModes:
- ReadWriteOnce
hostPath:
path: /data/postgres-pv
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pvc
labels:
type: local
app: postgres
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumeName: postgres-pv
---
apiVersion: v1
kind: Secret
metadata:
name: postgres-credentials
type: Opaque
data:
user: YWRtaW4=
password: password==
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres-container
image: postgres:9.6.6
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: POSTGRES_DB
value: kubernetes_django
ports:
- containerPort: 5432
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-volume-mount
volumes:
- name: postgres-volume-mount
persistentVolumeClaim:
claimName: postgres-pvc
---
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
ports:
- protocol: TCP
port: 5432
targetPort: 5432
selector:
app: postgres
Nothing fails to deploy, but the pod gets stuck in a CrashLoopBackOff.
Thanks for the help!
storageClassName: manual capacity: storage: 10Gi
Google persistant volumes cannot be lower than 10Gi in GCE, and I think it is the same in GKE. Why did you not created a Google cloud SQL Postgres instance, it seems much more easier to me. :) – ThisIsMyName