我正在尝试使用Kubernetes部署PostgreSQL数据库,遇到了与数据目录相关的错误。下面是我的部署的YAML配置:
apiVersion: apps/v1
kind: Deployment
metadata:
name: db
spec:
replicas: 1
selector:
matchLabels:
app: db
template:
metadata:
labels:
type: deployment
app: db
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: affinity-type
operator: In
values:
- postgres
tolerations:
- key: "key"
value: "database"
operator: "Equal"
effect: "NoSchedule"
volumes:
- name: db-nfs-pvc
persistentVolumeClaim:
claimName: db-nfs-pvc
- name: init-volume
configMap:
name: db-init
- name: db-hba-conf
configMap:
name: hba-init
- name: db-postgresql-conf
configMap:
name: postgresql-conf-init
containers:
- name: db
image: postgres:14-bullseye
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5432
envFrom:
- secretRef:
name: db
volumeMounts:
- name: db-nfs-pvc
mountPath: /var/lib/postgresql/data
subPath: pgdata
- name: init-volume
mountPath: /docker-entrypoint-initdb.d/
- name: db-postgresql-conf
mountPath: /var/lib/postgresql/data/postgresql.conf
subPath: postgresql.conf
- name: db-hba-conf
mountPath: /var/lib/postgresql/data/pg_hba.conf
subPath: pg_hba.conf
command:
- "postgres"
- "-c"
- "config_file=/var/lib/postgresql/data/postgresql.conf"
- "-c"
- "hba_file=/var/lib/postgresql/data/pg_hba.conf"
字符串
POSTGRESQL_ENV:
POSTGRES_USER=admin
POSTGRES_PASSWORD=password
PGDATA=/var/lib/postgresql/data/pgdata
型
问题:使用上述配置部署PostgreSQL数据库时,pod无法启动,并且日志显示以下错误:
postgres: could not access directory "/var/lib/postgresql/data/pgdata": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
型
kubectl describe pod:
0/11 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/11 nodes are available: 11 No preemption victims found for incoming pod.
型
其他信息:
- 我已经验证了PersistentVolumeClaim db-nfs-pvc已绑定且可用。
- 我已经包含了环境变量POSTGRES_USER、POSTGRES_PASSWORD和PGDATA来指定PostgreSQL用户、密码和数据目录路径。
1条答案
按热度按时间nvbavucw1#
看看bitnami的postgresql掌舵图,尝试从头开始将postgresql部署到kubernetes上并不是一个明智的举动。
https://github.com/bitnami/charts/tree/main/bitnami/postgresql