docker - Kubernetes - statefulSet 和卷权限
问题描述
我正在尝试创建如下所示的 statefulSet,在其中运行 init 容器之前在主容器中使用卷数据之前应用权限,但出现权限错误,如下所示
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgresql
spec:
serviceName: postgresql-headless
replicas: 1
selector:
matchLabels:
app: awx
template:
metadata:
name: postgresql
labels:
app: awx
spec:
securityContext:
fsGroup: 1001
serviceAccountName: awx
initContainers:
- name: init-chmod-data
image: docker.local/data/awx/bitnami/minideb/minideb:1.0
command:
- /bin/sh
- -cx
- |
echo "current user id: `id`"
mkdir -p /bitnami/postgresql/data
chmod 700 /bitnami/postgresql/data
find /bitnami/postgresql/data -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \
xargs chown -R 1001:1001
securityContext:
runAsUser: 1001
volumeMounts:
- name: data
mountPath: /bitnami/postgresql/data
subPath: ""
containers:
- name: postgresql
image: docker.local/bitnami/postgresql:11.6.0-debian-10-r5
securityContext:
runAsUser: 1001
env:
- name: POSTGRESQL_PASSWORD
value: "p@ssw0rd"
volumeMounts:
- name: data
mountPath: /bitnami/postgresql/data
subPath: ""
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: cinder
当我运行此规范时,它在 init 容器上失败:
kubectl -n mynamespace logs postgresql-0 -c init-chmod-data
+ id
current user id: uid=1001(postgresql) gid=1001(postgresql) groups=1001(postgresql)
+ echo current user id: uid=1001(postgresql) gid=1001(postgresql) groups=1001(postgresql)
+ mkdir -p /bitnami/postgresql/data
+ chmod 700 /bitnami/postgresql/data
chmod: changing permissions of '/bitnami/postgresql/data': Operation not permitted
但是,当我在 docker 本地运行 init 容器中使用的映像时,我可以更改这些权限:
sudo docker image ls | grep 1.0 | grep minideb
docker.local/data/awx/bitnami/minideb/minideb 1.0 698636b178a6 2 hours ago 53.7MB
sudo docker run -it --name minideb 698636b178a6
postgresql@248dcad0e738:/$ mkdir -p /bitnami/postgresql/data
postgresql@248dcad0e738:/$ chmod 700 /bitnami/postgresql/data
postgresql@248dcad0e738:/$
minideb 映像已修改如下,因为我无法以 root 身份运行容器:
FROM docker.local/bitnami/minideb:stretch
USER 0
RUN groupadd --gid 1001 postgresql && useradd --uid 1001 --gid 1001 postgresql
RUN mkdir -p /bitnami/postgresql ; chown -R 1001:1001 /bitnami/postgresql
USER 1001
知道我做错了什么吗?谢谢!
解决方案
移除陈旧的 pvc 后修复
推荐阅读
- sql-server - 为什么我无法从 SQL Server Management Studio 远程连接 SQL Server Report Server?
- php - SQLITE 创建具有唯一列的表
- android - Android:什么是 https://t.tcplive.net
- javascript - 当用户单击链接时,如何通过请求将身份验证令牌从本地存储发送到后端
- timeout - 在 OpenSeaDragon 中,如何忽略加载瓦片的超时错误?
- image - 寻找固定数据集图像
- python - concurrent.futures.ThreadPoolExecutor / 多线程内存不足(已终止)
- android - Galaxy Fold 保护屏
- mysql - 找不到与 Union 中的列列表匹配的 FULLTEXT 索引
- swift - Swift iOS 使用 SIP 服务器连接和注册