[英]Connect Kubernetes Postgres pod to existing database stored on persistent volume
我正在嘗試將在 Kubernetes 中運行的新 Wiki.js 應用程序實例連接到從先前應用程序實例創建並存儲在持久卷中的 Postgres 數據庫。 我得到一個CrashLoopBackOff
嘗試啟動 postgres pod,查看它們顯示的日志:
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: directory "/var/lib/postgresql/data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/var/lib/postgresql/data" or run initdb
with an argument other than "/var/lib/postgresql/data".
如您所見,它嘗試調用initdb
失敗,因為已經存在數據...我的主要問題是如何配置以使用現有數據而不是嘗試創建新數據庫???
我的 kubernetes postgres 部署配置:
Name: postgres
Namespace: wiki
CreationTimestamp: Fri, 23 Aug 2019 22:17:44 +0000
Labels: app=postgres
Annotations: deployment.kubernetes.io/revision: 36
Selector: app=postgres
Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 1 max unavailable, 1 max surge
Pod Template:
Labels: app=postgres
Containers:
postgres:
Image: postgres:11.5
Port: 5432/TCP
Host Port: 0/TCP
Environment:
POSTGRES_USER: <redacted>
POSTGRES_PASSWORD: <redacted>
POSTGRES_DB: postgresdb
Mounts:
/var/lib/postgresql/data from postgresdb (rw)
Volumes:
postgresdb:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: postgres-persistant-storage-postgres-0
ReadOnly: false
如前所述,只是試圖指向現有的 postgres 數據庫,而不是讓它嘗試創建和初始化一個全新的數據庫,任何幫助將不勝感激!
更新
當我猛擊 Postgres pod 並檢查/var/lib/postgresql/data
目錄時,我確實看到了 PG_VERSION 文件以及一堆其他 db 文件(屏幕截圖)。 PG_VERSION 文件本身包含字符串11
,這很有意義,因為我們使用的是 Postgres 11.5。 不幸的是,由於某種原因,它仍然無法識別它:(
這也是我的 deployment.yaml 規范:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "60"
creationTimestamp: "2019-08-23T22:17:44Z"
generation: 184
labels:
app: postgres
name: postgres
namespace: wiki
resourceVersion: "91329506"
selfLink: /apis/extensions/v1beta1/namespaces/wiki/deployments/postgres
uid: d441d0d8-c5f3-11e9-bc53-9676559ad387
spec:
progressDeadlineSeconds: 2147483647
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: postgres
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: postgres
spec:
containers:
- env:
- name: POSTGRES_USER
value: postgresadmin
- name: POSTGRES_PASSWORD
value: <redacted>
- name: POSTGRES_DB
value: wiki
image: postgres:11.5
imagePullPolicy: IfNotPresent
name: postgres
ports:
- containerPort: 5432
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgresdb
dnsPolicy: ClusterFirst
hostname: postgrespod
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
subdomain: postgres
terminationGracePeriodSeconds: 30
volumes:
- name: postgresdb
persistentVolumeClaim:
claimName: wiki-data
看起來圖像檢查的是一個名為$PGDATA/PG_VERSION
的匹配文件,以決定它是否需要初始化。 見https://github.com/docker-library/postgres/blob/04f28840134bdaf72e4cd6e4a5300e9ceb5ea013/docker-entrypoint.sh#L211-L214
您必須使該文件存在於您的卷中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.