问题描述
我一直在将一个项目从 kube 转移到 openshift。在 minikube 中,该项目运行良好,但在 minishift 中出现错误
— Crash loop back off
这是小班日志
[WARN] $TIMEZONE not set.
[INFO] Docker date set to: Tue Apr 20 17:39:02 UTC 2021
[INFO] $PHP_FPM_ENABLE not set. PHP-FPM support disabled.
[INFO] $CUSTOM_HTTPD_CONF_DIR not set. No custom include directory added.
[INFO] Starting Server version: Apache/2.2.15 (Unix)
whoami: cannot find name for user ID 1000140000
这里是相关的deployment.yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: occtool
name: occtool
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: occtool
strategy: {}
template:
Metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.network/backend: "true"
io.kompose.network/frontend: "true"
io.kompose.service: occtool
spec:
containers:
- image: private.registry.com/image:tag
imagePullPolicy: IfNotPresent
name: occtool
ports:
- containerPort: 80
- containerPort: 443
resources: {}
restartPolicy: Always
status: {}
这里是 Dockerfile
FROM cytopia/apache-2.2:0.9
# lines that copied files were omitted for convenience
USER root
我没有找到太多相关信息。 USER root
最初已被省略,因此用户是 apache。使用 minishift ssh 和 docker exec 我注意到用户 apache 不存在于 pod 中,但是在构建映像时我无法运行命令来创建用户,因为该用户确实存在于映像中。我相信这是问题的根源,但是我还没有找到在openshift中创建用户的方法,也不知道为什么在构建pod时删除了用户。
解决方法
OpenShift 忽略来自 Dockerfiles 的 db.collectionName.createIndex( { "createdAt": 1 },{ expireAfterSeconds: 120 } )
指令,而是为容器中的用户生成一个随机 UID。这背后有一些关于安全的想法。
来自 OpenShift documentation:
支持任意用户 ID
默认情况下,OpenShift Container Platform 使用任意分配的用户 ID 运行容器。这提供了额外的安全性,防止进程因容器引擎漏洞而逃逸容器,从而实现对主机节点的升级权限。
对于支持以任意用户身份运行的映像,映像中的进程可能写入的目录和文件应归根组所有,并且可由该组读取/写入。要执行的文件也应该有组执行权限。