【问题标题】:Not able to create Prometheus in K8S cluster无法在 K8S 集群中创建 Prometheus
【发布时间】:2019-06-28 03:01:17
【问题描述】:

我正在尝试在我的 K8S 集群上安装 Prometheus

当我运行命令时

kubectl get namespaces

我得到了以下命名空间:

default       Active   26h
kube-public   Active   26h
kube-system   Active   26h
monitoring    Active   153m
prod          Active   5h49m

现在我想通过

创建 Prometheus
helm install stable/prometheus --name prom -f k8s-values.yml

我得到了错误:

错误:发布舞会演示失败:命名空间“默认”被禁止: 用户“system:serviceaccount:kube-system:default”无法获取资源 命名空间“default”中的 API 组“”中的“命名空间”

即使我切换到monitoring ns,我也会遇到同样的错误,

k8s-values.yml 如下所示

rbac:
  create: false
server:
  name: server

  service:
    nodePort: 30002
    type: NodePort

知道这里可能缺少什么吗?

【问题讨论】:

标签: kubernetes google-cloud-platform cloud prometheus kubernetes-helm


【解决方案1】:

您收到此错误是因为您在未授予正确权限的情况下使用 RBAC。

授予分蘖权限:
取自https://github.com/helm/helm/blob/master/docs/rbac.md

示例:具有集群管理员角色的服务帐户 在 rbac-config.yaml 中:

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

注意:cluster-admin 角色是在 Kubernetes 集群中默认创建的,因此您不必显式定义它。

$ kubectl create -f rbac-config.yaml
serviceaccount "tiller" created
clusterrolebinding "tiller" created
$ helm init --service-account tiller

为 prometheus 创建服务帐号:
rbac.create的值改为true

rbac:
  create: true
server:
  name: server

  service:
    nodePort: 30002
    type: NodePort

【讨论】:

  • 非常感谢,现在当我尝试创建它(最后一个 yaml)时,由于缺少 KindapiVersion 而出现错误,我尝试使用服务但没有成功,知道吗?跨度>
  • 珍妮使用@rom 提供的指南:github.com/helm/helm/blob/master/docs/rbac.md
  • 我无法使用上面的 yaml 创建服务帐户,我错过了什么吗?
  • yaml文件第一行丢失:apiVersion: v1,添加后重试
  • 请查看您是否也可以在这里提供帮助:stackoverflow.com/questions/54535869/…
【解决方案2】:

查看 prometheus 操作符以启动 prometheus 堆栈中的所有监控服务。 下面的链接很有帮助 https://github.com/coreos/prometheus-operator/tree/master/contrib/kube-prometheus/manifests

所有清单都列在那里。浏览这些文件并在 k8s 集群中部署您需要监控的任何内容

【讨论】:

    猜你喜欢
    • 2021-03-03
    • 2019-04-13
    • 2019-07-13
    • 2022-08-18
    • 2016-01-02
    • 2019-05-04
    • 2014-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多