kubernetes - 如何将容器卷(非 root 用户)挂载到 Kubernetes 主机上的 root 用户?
问题描述
当我尝试将应用程序日志卷从容器挂载到主机时出现错误:不允许操作
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
initContainers:
- name: volume-mount-permission
image: xx.xx.xx.xx/orchestration/credit-card
command:
- sh
- -c
- chown -R 1000:1000 /opt/payara/appserver/glassfish/logs/credit-card
- chgrp 1000 /opt/payara/appserver/glassfish/logs/credit-card
volumeMounts:
- name: card-corp-logs
mountPath: /opt/payara/appserver/glassfish/logs/credit-card
readOnly: false
containers:
- name: credit-card
image: xx.xx.xx.xx/orchestration/credit-card
imagePullPolicy: Always
securityContext:
privileged: true
runAsUser: 1000
ports:
- name: credit-card
containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
successThreshold: 1
volumeMounts:
- name: override-setting-storage
mountPath: /p/config
- name: credit-card-teamsite
mountPath: /var/credit-card/teamsite/card_corp
容器路径 - /opt/payara/appserver/glassfish/logs/credit-card 到 hostPath
任何人都可以帮我解决我在部署 yml 文件中出错的地方。
解决方案
securityContext:
runAsUser: 1000
runAsGroup: 3000
意味着您不能chown 1000:1000
,因为该用户不是组的成员 1000
可能你会想要运行它initContainer:
以runAsUser: 0
允许它执行任意chown
操作
您还截断了您的 YAML,该 YAML 将指定volumes:
您正在挂载的YAML volumeMounts:
- 您有可能尝试挂载的卷类型 - 无论您的readOnly: false
声明如何 - 都无法修改。ConfigMap
, Secret
, Downward API 和其他一些 API 也不会响应突变请求,即使root
.
推荐阅读
- javascript - 在元素上切换类,忽略除一个孩子以外的所有孩子
- python - Python - 绘制带有数据间隙的numpy数组
- azure - 将 Azure 静态网站配置为不需要尾部斜杠
- java - 即使服务器错误,ResponseBuilder 也会提供 200 OK HTTP 响应
- android - Android:从“最近的应用程序”开始应用程序回到最后一个活动
- rubygems - Ruby:`require':无法加载此类文件
- excel - 为什么我的子程序在即时窗口 excel vba 中运行良好时无法工作
- google-cloud-build - Google Cloud Build - 无法更新子模块
- python - Write on a file the volume of a drive plus random text
- python - How to move every 500 files into different folders