Ilt*_*yas 2 node.js kubernetes
我正在使用带有集群内配置的Kubernetes javascript 客户端与集群进行交互。
我正在尝试获取工作列表
app.js(节点)
app.get("/", (req, res) => {
k8sApi2
.listNamespacedJob("default")
.then((res) => {
console.log(res.body);
res.send(res.body);
})
.catch((err) => console.log(err));
});
Run Code Online (Sandbox Code Playgroud)
但这是我得到的 pod 的日志。
这是我的部署
服务
此外,我创建了一个角色和一个角色绑定,但我仍然不知道是什么导致了这个问题。
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: node-apis
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: node-apis
rules:
- apiGroups:
- ""
- "apps"
- "batch"
resources:
- endpoints
- deployments
- pods
- jobs
verbs:
- get
- list
- watch
- create
- delete
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: node-apis
namespace: default
subjects:
- kind: ServiceAccount
name: node-apis
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: node-apis
Run Code Online (Sandbox Code Playgroud)
我是 Kubernetes 的新手,有什么帮助吗?
您需要通过在 pod 的规范部分中指定它来使用服务帐户。由于您没有这样做,它使用的default服务帐户没有允许操作的 Role 和 RoleBinding,从而导致forbidden错误。
spec:
serviceAccountName: node-apis
containers:
...
Run Code Online (Sandbox Code Playgroud)
或者,您可以default在 RoleBinding 中授予服务帐户权限
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: node-apis
namespace: default
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: node-apis
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2143 次 |
| 最近记录: |