我在pod上运行了一个postgres数据库。它运行没有问题,数据就在那里。有一个持久卷,其目的是保持数据,无论pod发生了什么。
但是,当我重新启动服务器时,数据库显示为空。但是,卷已安装且文件位于文件系统中,包括服务器和容器中的文件。
我的数据库中没有关系/表格或任何内容:
(在吊舱内)
psql (9.6.2)
Type "help" for help.
information_system=# \d
我的机器上的 ls
,其中卷是:
blas@server:~$ sudo ls -l /tmp/data/postgres/
total 120
drwx------ 6 999 docker 4096 Oct 30 11:21 base
drwx------ 2 999 docker 4096 Oct 30 11:22 global
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_clog
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_commit_ts
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_dynshmem
-rw------- 1 999 docker 4490 Oct 30 11:21 pg_hba.conf
-rw------- 1 999 docker 1636 Oct 30 11:21 pg_ident.conf
drwx------ 4 999 docker 4096 Oct 30 11:21 pg_logical
drwx------ 4 999 docker 4096 Oct 30 11:21 pg_multixact
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_notify
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_replslot
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_serial
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_snapshots
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_stat
drwx------ 2 999 docker 4096 Oct 30 11:53 pg_stat_tmp
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_subtrans
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_tblspc
drwx------ 2 999 docker 4096 Oct 30 11:21 pg_twophase
-rw------- 1 999 docker 4 Oct 30 11:21 PG_VERSION
drwx------ 3 999 docker 4096 Oct 30 11:21 pg_xlog
-rw------- 1 999 docker 88 Oct 30 11:21 postgresql.auto.conf
-rw------- 1 999 docker 22205 Oct 30 11:21 postgresql.conf
-rw------- 1 999 docker 37 Oct 30 11:21 postmaster.opts
-rw------- 1 999 docker 85 Oct 30 11:21 postmaster.pid
安装卷的pod上的 ls
:
root@information-system-deployment-5dccfcb7c9-54trz:/var/lib/postgresql/data# ls -l
total 120
drwx------ 6 postgres postgres 4096 Oct 30 11:21 base
drwx------ 2 postgres postgres 4096 Oct 30 11:22 global
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_clog
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_commit_ts
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_dynshmem
-rw------- 1 postgres postgres 4490 Oct 30 11:21 pg_hba.conf
-rw------- 1 postgres postgres 1636 Oct 30 11:21 pg_ident.conf
drwx------ 4 postgres postgres 4096 Oct 30 11:21 pg_logical
drwx------ 4 postgres postgres 4096 Oct 30 11:21 pg_multixact
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_notify
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_replslot
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_serial
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_snapshots
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_stat
drwx------ 2 postgres postgres 4096 Oct 30 11:55 pg_stat_tmp
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_subtrans
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_tblspc
drwx------ 2 postgres postgres 4096 Oct 30 11:21 pg_twophase
-rw------- 1 postgres postgres 4 Oct 30 11:21 PG_VERSION
drwx------ 3 postgres postgres 4096 Oct 30 11:21 pg_xlog
-rw------- 1 postgres postgres 88 Oct 30 11:21 postgresql.auto.conf
-rw------- 1 postgres postgres 22205 Oct 30 11:21 postgresql.conf
-rw------- 1 postgres postgres 37 Oct 30 11:21 postmaster.opts
-rw------- 1 postgres postgres 85 Oct 30 11:21 postmaster.pid
部署:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: information-system-deployment
spec:
selector:
matchLabels:
app: information-system-deployment
strategy:
type: Recreate
template:
metadata:
labels:
app: information-system-deployment
spec:
containers:
- image: my-registry:5000/information-system-db
name: information-system-db
env:
- name: POSTGRES_DB
value: information_system
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: information-system-db-secret
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: information-system-db-secret
key: password
ports:
- containerPort: 5432
name: is-db
volumeMounts:
- name: information-system-db-pv-volume
mountPath: /var/lib/postgresql/data
- image: my-registry:5000/information-system-test:latest
name: information-system
ports:
- containerPort: 5010
name: is
command: ["bash", "-c", "python main.py"]
volumes:
- name: information-system-db-pv-volume
persistentVolumeClaim:
claimName: information-system-db-claim
持续音量:
kind: PersistentVolume
apiVersion: v1
metadata:
name: information-system-db-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/data/postgres"
持久存储声明
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: information-system-db-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
答案 0 :(得分:2)
我认为您不应该将/tmp/*
目录用于主机路径。
/tmp/*
目录:https://askubuntu.com/questions/20783/how-is-the-tmp-directory-cleaned-up