k8s 部署 postgresql 报错:initdb: error: directory "/var/lib/postgresql/data" exists but is not
2021/12/1 19:11:02
本文主要是介绍k8s 部署 postgresql 报错:initdb: error: directory "/var/lib/postgresql/data" exists but is not,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
最近在 k8s 上部署 gitlab 时,底层存储使用的是 ceph,结果 postgresql 遇到以下报错:
$ kubectl -n gitlab logs postgresql-76d969dd56-m79wm The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. initdb: error: directory "/var/lib/postgresql/data" exists but is not empty It contains a lost+found directory, perhaps due to it being a mount point. Using a mount point directly as the data directory is not recommended. Create a subdirectory under the mount point.
postgresql yaml 文件:
# pv apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgresql-ceph-pvc namespace: gitlab spec: storageClassName: ceph-leffss accessModes: - ReadWriteOnce resources: requests: storage: 20Gi --- apiVersion: v1 kind: Service metadata: name: postgresql namespace: gitlab labels: app: gitlab tier: postgreSQL spec: ports: - port: 5432 selector: app: gitlab tier: postgreSQL --- apiVersion: apps/v1 kind: Deployment metadata: name: postgresql namespace: gitlab labels: app: gitlab tier: postgreSQL spec: replicas: 1 selector: matchLabels: app: gitlab tier: postgreSQL strategy: type: Recreate template: metadata: labels: app: gitlab tier: postgreSQL spec: #nodeSelector: # gee/disk: "500g" containers: - image: hub.leffss.com/library/postgres:12.6-alpine #- image: harbor.boge.com/library/postgres:12.6-alpine name: postgresql env: - name: POSTGRES_USER value: gitlab - name: POSTGRES_DB value: gitlabhq_production - name: POSTGRES_PASSWORD value: bogeusepg - name: TZ value: Asia/Shanghai ports: - containerPort: 5432 name: postgresql livenessProbe: exec: command: - sh - -c - exec pg_isready -U gitlab -h 127.0.0.1 -p 5432 -d gitlabhq_production initialDelaySeconds: 110 timeoutSeconds: 5 failureThreshold: 6 readinessProbe: exec: command: - sh - -c - exec pg_isready -U gitlab -h 127.0.0.1 -p 5432 -d gitlabhq_production initialDelaySeconds: 20 timeoutSeconds: 3 periodSeconds: 5 # resources: # requests: # cpu: 100m # memory: 512Mi # limits: # cpu: "1" # memory: 1Gi volumeMounts: - name: postgresql mountPath: /var/lib/postgresql/data volumes: - name: postgresql persistentVolumeClaim: claimName: postgresql-ceph-pvc
解决方法:volumeMounts 中新增 subPath 参数
volumeMounts: - name: postgresql mountPath: /var/lib/postgresql/data subPath: data
参考:postgresql - How to have data persist in GKE kubernetes StatefulSet with postgres? - Stack Overflow
这篇关于k8s 部署 postgresql 报错:initdb: error: directory "/var/lib/postgresql/data" exists but is not的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-15在Kubernetes (k8s) 中搭建三台 Nginx 服务器怎么实现?-icode9专业技术文章分享
- 2024-11-05基于Kubernetes的自定义AWS云平台搭建指南
- 2024-11-05基于Kubernetes Gateway API的现代流量管理方案
- 2024-11-05在Kubernetes上部署你的第一个应用:Nginx服务器
- 2024-11-05利用拓扑感知路由控制Kubernetes中的流量
- 2024-11-05Kubernetes中的层次命名空间:更灵活的资源管理方案
- 2024-11-055分钟上手 Kubernetes:精简实用的 Kubectl 命令速查宝典!
- 2024-10-30K8s 容器的定向调度与亲和性
- 2024-10-28云原生周刊:K8s未来三大发展方向 丨2024.10.28
- 2024-10-25亚马逊弹性Kubernetes服务(EKS)实战:轻松搭建Kubernetes平台