我正在尝试将 postgres 服务部署到具有持久卷和持久卷声明的谷歌云 kubernetes,以为我的应用程序提供存储。
当我部署时,吊舱卡在CrashLoopBackOff
.
pod 的一个事件失败并显示以下消息:
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
这是我尝试使用 kubectl 部署的 yaml:
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
没有什么部署失败,但是 pod 卡在了 CrashLoopBackOff 中。
谢谢您的帮助!