【发布时间】:2021-07-30 11:11:56
【问题描述】:
我有一个图像,它是一个在端口 80 上运行的简单 Web 服务器。当我在本地运行它时,我得到:
The app is listening at http://localhost:80
一切都很好。
但是,当我将以下内容部署到 K8s 时,它会不断崩溃。
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: apps
labels:
app: my-app
spec:
replicas: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: myimage:dev
imagePullPolicy: Always
ports:
- containerPort: 80
其中一个 pod 的日志:
node:events:371
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (node:net:1298:21)
at listenInCluster (node:net:1363:12)
at Server.listen (node:net:1450:7)
at Function.listen (/app/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/app/index.js:17:5)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1342:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 80
}
为什么我的镜像能在本地机器上成功运行,而在 Kubernetes 上却失败了?
【问题讨论】:
-
尝试以管理员权限运行该进程。端口
-
确实如此。但是为什么图像在本地运行良好?使用
sudo docker run myimage是否会授予容器本身的管理员权限?
标签: node.js kubernetes networking