[英]K8s postgres not persisting data
I'm aiming to mount a persistent volume onto a postgres stateful set.我的目标是将持久卷安装到 postgres 有状态集上。 To test persistence, I:
为了测试持久性,我:
kubectl apply -f postgres.yml
)kubectl apply -f postgres.yml
)kubectl scale statefulset/postgresql-db --replicas 0 && kubectl delete statefulset/postgresql-db
)kubectl scale statefulset/postgresql-db --replicas 0 && kubectl delete statefulset/postgresql-db
)kubectl apply -f postgres.yml
)kubectl apply -f postgres.yml
) In my new deployment the db is empty, I expected the table and data to be persistent, why is this?在我的新部署中,数据库是空的,我希望表和数据是持久的,这是为什么?
I've been following a few articles to do this, notably:我一直在关注一些文章来做到这一点,特别是:
# kubectl apply -f postgres.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/tp/projects/bitbuyer"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgresql-db
spec:
serviceName: postgresql-db-service
selector:
matchLabels:
app: postgresql-db
replicas: 1
template:
metadata:
labels:
app: postgresql-db
spec:
containers:
- name: postgresql-db
image: postgres:latest
volumeMounts:
- name: postgres-pv
mountPath: /data
env:
- name: POSTGRES_PASSWORD
value: pgpassword
- name: PGDATA
value: /data/pgdata
volumes:
- name: postgres-pv
persistentVolumeClaim:
claimName: postgres-pvc
Issue could be possible due to问题可能是由于
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
subPath: pgdata
however this is what i am using for postgres然而,这就是我在 postgres 中使用的
https://github.com/harsh4870/Keycloack-postgres-kube.netes-deployment/blob/main/postgres.yaml https://github.com/harsh4870/Keycloack-postgres-kube.netes-deployment/blob/main/postgres.yaml
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
ports:
- name: pgql
port: 5432
targetPort: 5432
protocol: TCP
selector:
app: postgres
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: "postgres"
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:9.5
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
subPath: pgdata
env:
- name: POSTGRES_USER
value: root
- name: POSTGRES_PASSWORD
value: password
- name: POSTGRES_DB
value: kong
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- containerPort: 5432
terminationGracePeriodSeconds: 60
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: 10Gi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.