k8s安装之kube-state-metrics.yaml

概述

已经有了cadvisor、heapster、metric-server,几乎容器运行的所有指标都能拿到,但是下面这种情况却无能为力:

  • 我调度了多少个replicas?现在可用的有几个?
  • 多少个Pod是running/stopped/terminated状态?
  • Pod重启了多少次?
  • 我有多少job在运行中

而这些则是kube-state-metrics提供的内容,它基于client-go开发,轮询Kubernetes API,并将Kubernetes的结构化信息转换为metrics。

功能

kube-state-metrics提供的指标,按照阶段分为三种类别:

  • 1.实验性质的:k8s api中alpha阶段的或者spec的字段。

  • 2.稳定版本的:k8s中不向后兼容的主要版本的更新

  • 3.被废弃的:已经不在维护的。

指标类别包括:

  • CronJob Metrics
  • DaemonSet Metrics
  • Deployment Metrics
  • Job Metrics
  • LimitRange Metrics
  • Node Metrics
  • PersistentVolume Metrics
  • PersistentVolumeClaim Metrics
  • Pod Metrics
  • Pod Disruption Budget Metrics
  • ReplicaSet Metrics
  • ReplicationController Metrics
  • ResourceQuota Metrics
  • Service Metrics
  • StatefulSet Metrics
  • Namespace Metrics
  • Horizontal Pod Autoscaler Metrics
  • Endpoint Metrics
  • Secret Metrics
  • ConfigMap Metrics

以pod为例:

  • kube_pod_info
  • kube_pod_owner
  • kube_pod_status_phase
  • kube_pod_status_ready
  • kube_pod_status_scheduled
  • kube_pod_container_status_waiting
  • kube_pod_container_status_terminated_reason
  • ...

 

---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  namespace: kube-system
  name: kube-state-metrics-resizer
rules:
- apiGroups: [""]
  resources:
  - pods
  verbs: ["get"]
- apiGroups: ["apps"]
  resources:
  - deployments
  resourceNames: ["kube-state-metrics"]
  verbs: ["get", "update"]
- apiGroups: ["extensions"]
  resources:
  - deployments
  resourceNames: ["kube-state-metrics"]
  verbs: ["get", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: kube-state-metrics
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: kube-state-metrics-resizer
subjects:
- kind: ServiceAccount
  name: kube-state-metrics
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: kube-state-metrics
rules:
- apiGroups: [""]
  resources:
  - configmaps
  - secrets
  - nodes
  - pods
  - services
  - resourcequotas
  - replicationcontrollers
  - limitranges
  - persistentvolumeclaims
  - persistentvolumes
  - namespaces
  - endpoints
  verbs: ["list", "watch"]
- apiGroups: ["extensions"]
  resources:
  - daemonsets
  - deployments
  - replicasets
  - ingresses
  verbs: ["list", "watch"]
- apiGroups: ["apps"]
  resources:
  - daemonsets
  - deployments
  - replicasets
  - statefulsets
  verbs: ["list", "watch"]
- apiGroups: ["batch"]
  resources:
  - cronjobs
  - jobs
  verbs: ["list", "watch"]
- apiGroups: ["autoscaling"]
  resources:
  - horizontalpodautoscalers
  verbs: ["list", "watch"]
- apiGroups: ["policy"]
  resources:
  - poddisruptionbudgets
  verbs: ["list", "watch"]
- apiGroups: ["certificates.k8s.io"]
  resources:
  - certificatesigningrequests
  verbs: ["list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
# kubernetes versions before 1.8.0 should use rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: kube-state-metrics
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kube-state-metrics
subjects:
- kind: ServiceAccount
  name: kube-state-metrics
  namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kube-state-metrics
  namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
  name: kube-state-metrics
  namespace: kube-system
  labels:
    k8s-app: kube-state-metrics
  annotations:
    prometheus.io/scrape: 'true'
spec:
  ports:
  - name: http-metrics
    port: 8080
    targetPort: http-metrics
    protocol: TCP
  - name: telemetry
    port: 8081
    targetPort: telemetry
    protocol: TCP
  selector:
    k8s-app: kube-state-metrics
---
apiVersion: apps/v1
# Kubernetes version 1.8.x should use apps/v1beta2
# Kubernetes versions before 1.8.0 should use apps/v1beta1 or extensions/v1beta1
kind: Deployment
metadata:
  name: kube-state-metrics
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: kube-state-metrics
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: kube-state-metrics
    spec:
      serviceAccountName: kube-state-metrics
      containers:
      - name: kube-state-metrics
        image: harbor.xxx.cn/3rd_part/kube-state-metrics:v1.6.0
        ports:
        - name: http-metrics
          containerPort: 8080
        - name: telemetry
          containerPort: 8081
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          timeoutSeconds: 5
      - name: addon-resizer
        image: harbor.xxx.cn/3rd_part/addon-resizer:1.8.4
        resources:
          limits:
            cpu: 150m
            memory: 50Mi
          requests:
            cpu: 150m
            memory: 50Mi
        env:
          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: MY_POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        command:
          - /pod_nanny
          - --container=kube-state-metrics
          - --cpu=100m
          - --extra-cpu=1m
          - --memory=100Mi
          - --extra-memory=2Mi
          - --threshold=5
          - --deployment=kube-state-metrics

 

转载于:https://www.cnblogs.com/aguncn/p/10905444.html

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

<p> <span style="font-size:16px;"></span><span style="font-size:20px;"><strong>一、prometheus简介</strong></span> </p> <p> <span style="font-size:16px;"><strong> </strong></span> </p> <p> <strong> Prometheus是一个开源的系统监控和告警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF维护管理的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,prometheus支持多种exporter采集数据,还支持通过pushgateway进行数据上报,<span style="color:#494949;">Prometheus再</span><span style="color:#494949;">性能上可支撑上万台规模的集群。</span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:20px;"><strong><span style="color:#494949;">二、prometheus架构图</span></strong></span> </strong> </p> <strong> </strong> <p> <strong><span style="color:#494949;"><img src="https://img-bss.csdn.net/202004201352387874.png" alt="" /><br /></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:20px;"><strong>三、prometheus组件介绍</strong></span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;"></span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">1.Prometheus Server: 用于收集和存储时间序列数据。</span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">2.Client Library: 客户端库,检测应用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的当前状态发送到prometheus server端。</span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">3.Exporters: prometheus支持多种exporter,通过exporter可以采集metrics数据,然后发送到prometheus server端</span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">4.Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去重,分组,并路由到相应的接收方,发出报警,常见的接收方式有:电子邮件,微信,钉钉, slack等。</span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">5.Grafana:监控仪表盘</span> </strong> </p> <strong> </strong> <p style="text-align:left;"> <strong> <span style="font-size:16px;color:#323232;">6.pushgateway: 各个目标主机可上报数据到pushgatewy,然后prometheus server统一从pushgateway拉取数据。</span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:20px;"><strong><span></span></strong></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:20px;"><strong><span>四、课程亮点</span></strong></span><strong><span style="font-size:16px;"><br /></span></strong> </strong> </p> <strong> </strong> <p> <img src="https://img-bss.csdn.net/202004201352522795.png" alt="" /></p> <strong> </strong> <p> <strong> <strong><span style="font-size:16px;"></span></strong> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:20px;"><strong><span></span></strong></span><span style="font-size:20px;"><strong><span>五、效果图展示</span></strong></span></strong> </p> <p> <strong><span style="font-size:20px;"><strong><span><img src="https://img-bss.csdn.net/202004201353077268.png" alt="" /><br /></span></strong></span></strong> </p> <strong> </strong> <p> <strong><span style="font-size:20px;"><strong><img src="https://img-bss.csdn.net/202004201353245111.png" alt="" /><br /></strong></span></strong> </p> <p> <strong><span style="font-size:20px;"><strong><img src="https://img-bss.csdn.net/202004201353384468.png" alt="" /><br /></strong></span></strong> </p> <p> <strong><span style="font-size:20px;"><strong><img src="https://img-bss.csdn.net/202004201354069425.png" alt="" /><br /></strong></span></strong> </p> <p> <strong><span style="font-size:20px;"><strong><img src="https://img-bss.csdn.net/202004201354193720.png" alt="" /><br /></strong></span></strong> </p> <p> <strong> <span style="font-size:20px;"><strong>六、讲师简介</strong></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:16px;"><span style="color:#000000;">先超(lucky)</span><span style="color:#000000;">:</span></span><span style="color:#000000;font-size:16px;">高级运维工程师、资深DevOps工程师,在互联网上市公司拥有多年一线运维经验,主导过亿级pv项目的架构设计和运维工作</span><span style="color:#000000;font-size:16px;"><br /></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:16px;"><span style="color:#000000;font-size:16px;">主要研究方向:</span><span style="color:#000000;font-size:16px;"><br /></span></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:16px;"><span style="color:#000000;font-size:16px;">1.云计算方向:</span><span style="font-size:40px;color:#000000;"></span><span style="color:#000000;font-size:16px;">容器</span></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:16px;"><span style="color:#000000;font-size:16px;">(kubernetes、docker),虚拟化(kvm、Vmware vSphere),微服务(istio),PaaS(openshift),IaaS(openstack)等</span><span style="font-size:27px;color:#000000;"><br /></span><span style="color:#000000;font-size:16px;">2.系统/运维方向:</span><span style="font-size:40px;color:#000000;"></span><span style="font-size:39px;color:#000000;"></span><span style="color:#000000;font-size:16px;">linux系统下的常用组件(nginx,tomcat,elasticsearch,zookeeper,kafka等),DevOps(Jenkins+gitlab+sonarqube+nexus+k8s),CI/CD,监控(zabbix、prometheus、falcon)等</span><span style="font-size:39px;color:#000000;"><br /></span></span> </strong> </p> <strong> </strong> <p> <strong> <span style="font-size:39px;color:#000000;"></span> </strong> </p> <strong></strong><strong></strong><strong></strong> <p> <strong><span style="font-size:18px;">七、课程大纲</span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202004201355254800.png" alt="" /><br /></span></strong> </p> <p> <strong><span style="font-size:24px;"><img src="https://img-bss.csdn.net/202004201355386613.png" alt="" /><br /></span></strong> </p> <p> <strong><span style="font-size:24px;"><img src="https://img-bss.csdn.net/202004201356062136.png" alt="" /><br /></span></strong> </p> <p> <strong><span style="font-size:24px;"><img src="https://img-bss.csdn.net/202004201356218012.png" alt="" /><br /></span></strong> </p>
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值