简体   繁体   English

通过微服务获取 Kube.netes pods 信息

[英]Get Kubernetes pods information through microservice

When sending request to api, it throws NPE at api.listPodForAllNamespaces step.当向 api 发送请求时,它会在 api.listPodForAllNamespaces 步骤抛出 NPE。 Could you please advise, what should be the correct configuration here?能否请您指教,这里的正确配置应该是什么?

As the error says:正如错误所说:

pods is forbidden: User \"system:serviceaccount:sds-test:default\" cannot list resource \"pods\"

This means that the service account default in the namespace sds-test does not have the appropriate permissions to list pods.这意味着命名空间sds-test中的服务帐户default没有适当的权限来列出 pod。 You are probably not specifying a service account when you deploy.您可能在部署时没有指定服务帐户。 K8s will automatically assign you the default service account. K8s 会自动为您分配default服务帐户。

You need to create a ServiceAccount .您需要创建一个ServiceAccount Grant it the required access using a Role and RoleBinding .使用RoleRoleBinding授予它所需的访问权限。 Then update your Deployment / Pod to use your newly created ServiceAccount .然后更新您的Deployment / Pod以使用您新创建的ServiceAccount Details of which can be found here可在 此处找到详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM