如何安装kube-state-metrics

时间:2017-10-24 22:23:25

标签: kubernetes prometheus

我想收集K8中POD的指标。 kube-state-metrics看起来不错。我无法关注README。我追查make container。有没有简单的方法来部署kube-state-metrics

UPDATE1

kubectl apply -f kubernetes。低于错误。我认为,版本不匹配。知道怎么克服吗?

serviceaccount "kube-state-metrics" configured
service "kube-state-metrics" configured
Error from server (BadRequest): error when creating "kubernetes/kube-state-metrics-cluster-role-binding.yaml": ClusterRoleBinding in version "v1" cannot be handled as a ClusterRoleBinding: no kind "ClusterRoleBinding" is registered for version "rbac.authorization.k8s.io/v1"
Error from server (BadRequest): error when creating "kubernetes/kube-state-metrics-cluster-role.yaml": ClusterRole in version "v1" cannot be handled as a ClusterRole: no kind "ClusterRole" is registered for version "rbac.authorization.k8s.io/v1"
Error from server (BadRequest): error when creating "kubernetes/kube-state-metrics-deployment.yaml": Deployment in version "v1beta2" cannot be handled as a Deployment: no kind "Deployment" is registered for version "apps/v1beta2"
Error from server (BadRequest): error when creating "kubernetes/kube-state-metrics-role-binding.yaml": RoleBinding in version "v1" cannot be handled as a RoleBinding: no kind "RoleBinding" is registered for version "rbac.authorization.k8s.io/v1"
Error from server (BadRequest): error when creating "kubernetes/kube-state-metrics-role.yaml": Role in version "v1" cannot be handled as a Role: no kind "Role" is registered for version "rbac.authorization.k8s.io/v1"

2 个答案:

答案 0 :(得分:4)

你很亲密。

同一页面有Kubernetes Deployment部分。

https://github.com/kubernetes/kube-state-metrics#kubernetes-deployment

克隆github存储库后,您可以简单地运行:

kubectl apply -f kubernetes

您可以在此处仔细查看部署文件:

https://github.com/kubernetes/kube-state-metrics/tree/master/kubernetes

---更新---

如果你正在运行旧版本的K8,它仍然使用部署版本v1beta1而没有RBAC尝试以下(yaml文件)示例:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: kube-state-metrics-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: kube-state-metrics
        version: "v0.4.1"
    spec:
      containers:
      - name: kube-state-metrics
        image: gcr.io/google_containers/kube-state-metrics:v0.4.1
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/scrape: 'true'
  name: kube-state-metrics
  labels:
    k8s-app: kube-state-metrics
spec:
  ports:
  - name: http-metrics
    port: 8080
    protocol: TCP
  selector:
    k8s-app: kube-state-metrics

答案 1 :(得分:0)

对于UPDATE1中的错误(在我的问题中),我在该回购中使用了以前的版本yaml文件。您可以在此处查看更改 - > https://github.com/kubernetes/kube-state-metrics/commit/24ab2b6e6d7d97690538cabc977c4afc3dcdc822