go - 在非默认命名空间中部署时,Cluster Config 无法获取 Pod

标签 go kubernetes client-go

当我将 golang 服务部署到除 default 命名空间之外的任何命名空间时,该服务无法检索任何命名空间上的 pod。部署在 default 命名空间上的相同服务使用 golang client-go api 完美运行。

这是安全问题吗?

谢谢。

最佳答案

这个问题是权限问题。由于您正在使用 rest.InClusterConfig(config) 创建客户端。这意味着它使用 pod 的服务帐户作为凭证。因此,请检查该服务帐户是否具有在任何命名空间中获取 pod 的权限。

if service account in the pod is not defined, then it will use default service account.

如果您的集群中启用了 RBAC,则检查该命名空间中的角色绑定(bind),以确定您的服务帐户是否具有权限。

# to see the list of role bindings in 'default' namespace
kubectl get rolebindings --namespace default

查看具体的rolebinding

kubectl get rolebindings ROLE-BINDING-NAME --namespace default -o yaml

您还可以创建角色和角色绑定(bind)来授予权限。要了解 RBAC 角色和角色绑定(bind),请参阅此处:https://kubernetes.io/docs/reference/access-authn-authz/rbac/

关于go - 在非默认命名空间中部署时,Cluster Config 无法获取 Pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53394844/

相关文章:

go - 在 Golang 结构中分配数据库列

go - 如何在 go 中模拟函数?

go - 如何从集群内 client-go api 调用中检索 kubectl describe pods <namespace> 中的所有数据

go - 如何使用 ServiceAccount Token 连接到 Kubernetes 集群?

kubernetes - "Ghost"kubernetes pod 卡在终止状态

go - 如何在 go 中获取指向类型化函数的函数指针?

go - 了解 Go 中的嵌入

kubernetes - openshift/kubernetes 与 glusterfs : how to prevent rounding of capacity size?

jenkins - 在 Jenkins 上设置 Kubernetes 插件