一步步学习k8s(四)

一步步学习k8s(三)

新一代容器监控Prometheus

Prometheus(普罗米修斯)是一个最初在SoundCloud上构建的监控系统。
在2012年成为社区开源项目,偶那个有非常活跃的开发人员和用户社区,为强调开源和独立维护,Promethues于2016年加入CNCF,成为继kubernetes之后的这第二个托管项目。
https://Prometheus.io
https://github.com/promethues

Prometheus的特点:

  • 多维数据模型:由度量名称和键值对标识的时间序列数据
  • 内置时间序列数据库:TSDB
  • promQL:一种灵活的查询语言,可以利用多维数据完成复杂查询
  • 基于HTTP的pull(拉取)方式采集时间序列数据(exporter)
  • 同时支持PushGateway组件收集数据
  • 通过服务发现或静态配置发现目标
  • 多种图形模式及仪表盘支持
  • 支持做为数据源接入Grafana

Prometheus的架构:
一步步学习k8s(四)_第1张图片

1、部署kube-state-metrics(收集k8s基本信息的软件)

在运维主机10.4.7.200

1.1、准备kebe-state-metrics镜像

官方地址:https://quay.io/repository/coreos/kube-state-metrics

[root@hdss7-200 ~]# docker pull quay.io/coreos/kube-state-metrics:v1.5.0
[root@hdss7-200 ~]# docker images |grep kube-state
quay.io/coreos/kube-state-metrics          v1.5.0          91599517197a   2 years ago     31.8MB
[root@hdss7-200 ~]# docker tag 91599517197a harbor.od.com/public/kube-state-metrics:v1.5.0
[root@hdss7-200 ~]# docker push harbor.od.com/public/kube-state-metrics:v1.5.0

1.2、准备资源配置清单

rbac.yaml
[root@hdss7-200 k8s-yaml]# mkdir kube-state-metrics
[root@hdss7-200 k8s-yaml]# cd kube-state-metrics/
[root@hdss7-200 kube-state-metrics]# vim rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: kube-state-metrics
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: clusterRole
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  name: kube-state-metrics
rules:
- apiGroups:
  _ ""
  resources:
  - configmaps
  - secrets
  - nodes
  - pods
  - services
  - resourcequotas
  - replicationcontrollers
  - limitranges
  - persistentvolumeclaims
  - persistentvolumes
  - namespaces
  - endpoints
  verbs:
  - list
  - watch
- apiGroups:
  - policy
  resources:
  - poddisruptionbudgets
  verbs:
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - daemonsets
  - deployments
  - replicasets
  verbs:
  - list
  - watch
- apiGroups:
  - apps
  resources:
  - statefulsets
  verbs:
  - list
  - watch
  apiGroups:
  - batch
   resources:
  - cronjobs
  - jobs
  verbs:
  - list
  - watch
- apiGroups:
  - autoscaling
  resources:
  - horizontalpodautoscalers
  verbs:
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/cluster-service: "true"
  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
dp.yaml
[root@hdss7-200 kube-state-metrics]# vim dp.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "2"
  labels:
    grafanak8sapp: "true"
    app: kube-state-metrics
  name: kube-state-metrics
  namespace: kube-system
spec:
  selector:
    matchLabels:
      grafanak8sapp: "true"
      app: kube-state-metrics
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        grafanak8sapp: "true"
        app: kube-state-metrics
    spec:
      containers:
      - name: kube-state-metrics
        image: harbor.od.com/public/kube-state-metrics:v1.5.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: http-metrics
          protocol: TCP
        readinessProbe:
          fallureThreshold: 3
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
      serviceAccountName: kube-state-metrics

1.3、应用资源配置清单

在任意一台运算节点上:


1.4、检查启动情况

2、部署node-exporter(收集k8s运算节点上基础设施信息的软件)

3、部署cadvisor(监控容器内部使用资源的重要工具)

4、部署blackbox-exporter

4.1、准备blackbox-exporter镜像

4.2、准备资源配置清单

4.3、应用资源配置清单

4.4、浏览器访问

5、部署Promethues

5.1、准备prometheus镜像

5.2、准备资源配置清单

5.3、准备prometheus的配置文件

5.4、应用资源配置清单

5.5、解析域名

5.6、浏览器访问

5.7、Prometheus监控内容

5.7.1、etcd
5.7.2、kubernetes-apiserver
5.7.3、kubernetes-kubelet
5.7.4、kubernetes-kube-state
5.7.5、traefik
5.7.6、blackbox*
5.7.7、kubernetes-pods*

5.8、修改traefix服务接入prometheus监控

5.9、修改dubbo-service服务接入prometheus

5.10、修改dubbo-consumer服务接入prometheus

6、部署Grafana

你可能感兴趣的:(K8S)