HELM 列表:无法列出命名空间"kube-system"中的配置映射



我已经在 kubernetes 8 集群上安装了 helm 2.6.2。 helm init工作正常。但是当我运行helm list时,它会给出此错误。

 helm list
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list configmaps in the namespace "kube-system"

如何修复此 RABC 错误消息?

一旦这些命令:

kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'      
helm init --service-account tiller --upgrade

运行,问题已解决。

更安全的答案

接受的答案提供了对 Helm 的完全管理员访问权限,这不是安全方面的最佳解决方案。通过更多的工作,我们可以限制 Helm 对特定命名空间的访问。有关更多详细信息,请参阅 Helm 文档。

$ kubectl create namespace tiller-world
namespace "tiller-world" created
$ kubectl create serviceaccount tiller --namespace tiller-world
serviceaccount "tiller" created

定义一个角色,允许 Tiller 像在role-tiller.yaml中一样管理tiller-world中的所有资源:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager
  namespace: tiller-world
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]

然后运行:

$ kubectl create -f role-tiller.yaml
role "tiller-manager" created

rolebinding-tiller.yaml

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding
  namespace: tiller-world
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: tiller-world
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io

然后运行:

$ kubectl create -f rolebinding-tiller.yaml
rolebinding "tiller-binding" created

之后,您可以运行 helm init 以在 tiller-world 命名空间中安装 Tiller。

$ helm init --service-account tiller --tiller-namespace tiller-world

现在,在所有命令前面加上--tiller-namespace tiller-world或在环境变量中设置TILLER_NAMESPACE=tiller-world

更多面向未来的答案

停止使用分舵机。Helm 3完全消除了对Tiller的需求。如果您使用的是 Helm 2,则可以使用 helm template 从 Helm 图表生成 yaml,然后运行 kubectl apply 将对象应用于 Kubernetes 集群。

helm template --name foo --namespace bar --output-dir ./output ./chart-template
kubectl apply --namespace bar --recursive --filename ./output -o yaml

Helm 使用"默认"服务帐户运行。您应该为其提供权限。

对于只读权限:

kubectl create rolebinding default-view --clusterrole=view --serviceaccount=kube-system:default --namespace=kube-system

对于管理员访问权限:例如:安装软件包。

kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default

默认服务帐户没有 API 权限。可能需要为 Helm 分配一个服务帐户,并为该服务帐户分配 API 权限。请参阅 RBAC 文档,了解如何向服务帐户授予权限:https://kubernetes.io/docs/admin/authorization/rbac/#service-account-permissions

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

kubectl apply -f your-config-file-name.yaml

然后更新 helm 安装以使用服务帐户:

helm init --service-account tiller --upgrade

我在尝试在离线模式下安装 tiller 时收到此错误,我认为"tiller"服务帐户没有足够的权限,但事实证明网络策略阻止了 tiller 和 API 服务器之间的通信。

解决方案是为舵柄创建一个网络策略,允许舵柄的所有出口通信

>如果不是kube-system export TILLER_NAMESPACE=<your-tiller-namespace>为我解决了<your-tiller-namespace>.这会将 Helm 客户端指向正确的 Tiller 命名空间。

如果您使用的是 AWS 中的 EKS 集群并面临禁止的问题(例如:forbidden: User ... cannot list resource "jobs" in API group "batch" in the namespace "default"那么这对我有用:

溶液:

  1. 确保您已配置 AWS
  2. 确保配置的用户具有访问群集的权限。

最新更新