local-path-provisioner
local-path-provisioner copied to clipboard
Database file not found when using Postgres
- deploy Postgres on k3s
- cd local path, cd data and would see nothing

- cd pod's mount path, cd data and would see files expected.

- touch some file in local path or pod's mount path(except data/), it's ok to see them on both sides
$ cat postgres-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-5432-pvc
namespace: middlewares
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: "local-path"
$ cat postgres-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
namespace: middlewares
spec:
serviceName: postgres-headless-svc
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:14
ports:
- containerPort: 5432
protocol: TCP
volumeMounts:
- name: time-zone
mountPath: /etc/localtime
- name: postgres-data
mountPath: /var/lib/postgresql
env:
- name: POSTGRES_PASSWORD
value: yourpassword
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-5432-pvc
- name: time-zone
hostPath:
path: /etc/localtime
---
apiVersion: v1
kind: Service
metadata:
name: postgres-headless-svc
namespace: middlewares
spec:
ports:
- port: 5432
targetPort: 5432
clusterIP: None
selector:
app: postgres
- name: postgres-data
mountPath: /var/lib/postgresql/data
if I mount the local path to pg's data folder, I can see the files.

Events seem no problem.
