我有两个容器:一个带有gcloud/gsutil和clickhouse (基于debian/buster-瘦,没有在Dockerfile中设置额外的用户或权限)和git-sync容器。我正在运行他们两个并排在一个锅与共享的音量。我在共享卷中使用git-sync容器中的sh脚本来提取存储库。这是显而易见的:
apiVersion: v1
kind: Pod
metadata:
name: ...
namespace: ...
annotations:
...
labels:
...
spec:
serviceAccountName: airflow
automountServiceAccountToken: true
volumes:
- name: sql
emptyDir: {}
containers:
- name: base
securityContext:
runAsUser: 65533
runAsGroup: 65533
imagePullPolicy: Always
image: clickhouse-client-gcloud:20.6.4.44
volumeMounts:
- name: sql
mountPath: /opt/sql
resources:
requests:
memory: "4000Mi"
cpu: "4"
limits:
memory: "8000Mi"
cpu: "4"
env:
- name: GS_SERVICE_ACCOUNT
valueFrom:
secretKeyRef:
name: ...
key: service_account.json
- name: git-sync
securityContext:
runAsUser: 65533
runAsGroup: 65533
image: k8s.gcr.io/git-sync/git-sync:v3.3.1
imagePullPolicy: Always
volumeMounts:
- name: sql
mountPath: /tmp/git/
resources:
requests:
memory: 300Mi
cpu: 500m
limits:
memory: 600Mi
cpu: 1000m
envFrom:
- configMapRef:
name: ...
- secretRef:
name: ...因此,我有gcloud和clickhouse客户机在一个容器中,sh/sql脚本在另一个容器中,它们彼此共享卷。第二个容器中有.sh脚本:
echo $GS_SERVICE_ACCOUNT >> service_account.json
gcloud auth activate-service-account --key-file=service_account.json档案结构:
opt/
- cloud_client
- sql
-- git-repo
--- sql
---- 00.raw
----- 01.current.sh当我运行pod时,对于客户端容器,我有下一个命令和参数:
cmds=["sh"],
arguments=["/opt/sql/git-repo/sql/00.raw/01.current.sh", f"{get_current_parsing_day()}"]但我得到了:
sh: 0: Can't open /opt/sql/git-repo/sql/00.raw/01.current.sh如果我使用sleep运行客户端容器,使用/bin/bash连接内部,并运行sh /opt/sql/git-repo/sql/00.raw/01.current.sh,则在创建文件时失败。
cannot create service_account.json: Permission denied
如果我继续,cd到那个存储库并运行sh 01.current.sh,那么我会得到gsutil错误:
WARNING: Could not setup log file in /.config/gcloud/logs, (Error: Could not create directory [/.config/gcloud/logs/2021.06.11]: Permission denied.
Please verify that you have permissions to write to the parent directory.)
ERROR: gcloud crashed (ValueError): No key could be detected.
If you would like to report this issue, please run the following command:
gcloud feedback
To check gcloud for common problems, please run the following command:
gcloud info --run-diagnostics但是密钥文件在那里,它是为服务帐户创建并包含JSON的.
我似乎有一个许可问题,但我不知道如何解决它?我希望从两个容器执行文件/脚本,并允许它们写入主容器。
发布于 2021-06-11 07:37:50
问题是在securityContext中,我运行了两个容器,但不是根(尽管它是不是一个好做法),但是这个uid没有在容器本身中定义。
securityContext:
runAsUser: 65533
runAsGroup: 65533一旦我删除并重新启动它,所有的事情都解决了。
https://stackoverflow.com/questions/67931391
复制相似问题