kubernetes - 挂载目录的所有权错误
问题描述
我有以下 kubernetes yaml 文件:
1 apiVersion: apps/v1
1 kind: Deployment
2 metadata:
3 name: postgres-deployment
4 spec:
5 replicas: 1
6 selector:
7 matchLabels:
8 component: postgres
9 template:
10 metadata:
11 labels:
12 component: postgres
13 spec:
14 securityContext:
15 runAsUser: 999
16 runAsGroup: 999
17 fsGroup: 999
18 volumes:
19 - name: postgres-storage
20 persistentVolumeClaim:
21 claimName: postgres-persistent-volume-claim
22 containers:
23 - name: postgres
24 image: prikshet/postgres
25 ports:
26 - containerPort: 5432
27 volumeMounts:
28 - name: postgres-storage
29 mountPath: /var/lib/postgresql/data
30 subPath: postgres
31 imagePullPolicy: Always
但是 pod 给出了以下日志:
2021-08-11 06:06:15.749 GMT [8] LOG: skipping missing configuration file "/var/lib/postgresql/data/postgresql.auto.conf"
2021-08-11 06:06:15.750 UTC [8] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
2021-08-11 06:06:15.750 UTC [8] HINT: The server must be started by the user that owns the data directory.
而显然我指定了 fsGroup、runAsUser 和 runAsGroup。什么可能导致此错误?
解决方案
我会像你一样使用 initContainer: 来 chmod ,这个答案可能会对你有所帮助。初始化容器和安全上下文