1、修改部署traefik时的traefik.toml
添加

[metrics][metrics.prometheus]entryPoint = "traefik"buckets = [0.1, 0.3, 1.2, 5.0]

2、更新configmap

[root@k8s-node1 ingress-tls]# kubectl delete configmap traefik-conf -n kube-system
configmap "traefik-conf" deleted
[root@k8s-node1 ingress-tls]# kubectl create configmap traefik-conf --from-file=traefik.toml -n kube-system
configmap/traefik-conf created

3、更新traefik

[root@k8s-node1 k8s]# kubectl delete -f traefik.yaml
deployment.extensions "traefik-ingress-lb" deleted
service "traefik-ingress-service" deleted
[root@k8s-node1 k8s]# kubectl apply  -f traefik.yaml
deployment.extensions/traefik-ingress-lb created
service/traefik-ingress-service created

4、查看metrics

[root@k8s-node1 k8s]# kubectl get svc -n kube-system
NAME                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                       AGE
kube-dns                  ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP        20d
kubernetes-dashboard      NodePort    10.111.224.80    <none>        443:31620/TCP                 5d
metrics-server            ClusterIP   10.109.127.41    <none>        443/TCP                       20d
tiller-deploy             ClusterIP   10.106.162.242   <none>        44134/TCP                     4d22h
traefik-ingress-service   NodePort    10.99.77.82      <none>        80:30789/TCP,8080:30982/TCP   27s
[root@k8s-node1 k8s]# curl 10.99.77.82:8080/metrics
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 7.9855e-05
go_gc_duration_seconds{quantile="0.25"} 0.000158223
go_gc_duration_seconds{quantile="0.5"} 0.000176201
go_gc_duration_seconds{quantile="0.75"} 0.000601692
go_gc_duration_seconds{quantile="1"} 0.000850208
go_gc_duration_seconds_sum 0.003399933
go_gc_duration_seconds_count 9
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 50
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 5.386144e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 2.4111976e+07
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.451309e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 184228
# HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started.
# TYPE go_memstats_gc_cpu_fraction gauge
go_memstats_gc_cpu_fraction 0.0011970080102388571
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 544768
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 5.386144e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 1.277952e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 8.323072e+06
# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 39401
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 0
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 9.601024e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.5698057871671152e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.
# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 93
# HELP go_memstats_mallocs_total Total number of mallocs.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 223629
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 6944
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16384
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 120840
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 131072
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 9.401776e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.209291e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 884736
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 884736
# HELP go_memstats_sys_bytes Number of bytes obtained from system.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 1.3838584e+07
# HELP go_threads Number of OS threads created
# TYPE go_threads gauge
go_threads 10
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.32
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 65536
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 10
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 2.4039424e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.56980577722e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 6.3414272e+07

5、修改prometheus-cm.yaml,将traefik-ingress配置进去

apiVersion: v1
kind: ConfigMap
metadata:name: prometheus-confignamespace: kube-ops
data:prometheus.yml: |global:scrape_interval: 15sscrape_timeout: 15sscrape_configs:- job_name: 'prometheus'static_configs:- targets: ['localhost:9090']- job_name: 'traefik'static_configs:- targets: ['traefik-ingress-service.kube-system.svc.cluster.local:8080']

更新configmap

[root@k8s-node1 prometheus]# kubectl apply -f prometheus-cm.yaml
configmap/prometheus-config configured

6、热更新prometheus

[root@k8s-node1 prometheus]# kubectl get services -n kube-ops
NAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
prometheus   NodePort   10.101.72.224   <none>        9090:31343/TCP   2d19h
[root@k8s-node1 prometheus]# curl -X POST "http://10.101.72.224:9090/-/reload"

7、访问dashboard
http://192.168.100.87:31343/targets

8、使用exporter监控应用
有一些应用可能没有自带/metrics接口供 Prometheus 使用,在这种情况下,我们就需要利用 exporter 服务来为 Prometheus 提供指标数据了。Prometheus 官方为许多应用就提供了对应的 exporter 应用,也有许多第三方的实现

创建prome-redis.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:name: redisnamespace: kube-ops
spec:template:metadata:annotations:prometheus.io/scrape: "true"prometheus.io/port: "9121"labels:app: redisspec:containers:- name: redisimage: redis:4resources:requests:cpu: 100mmemory: 100Miports:- containerPort: 6379- name: redis-exporterimage: oliver006/redis_exporter:latestresources:requests:cpu: 100mmemory: 100Miports:- containerPort: 9121
---
kind: Service
apiVersion: v1
metadata:name: redisnamespace: kube-ops
spec:selector:app: redisports:- name: redisport: 6379targetPort: 6379- name: promport: 9121targetPort: 9121
kubectl apply -f prome-redis.yaml
[root@k8s-node1 prometheus]# kubectl get pods -n kube-ops
NAME                          READY   STATUS    RESTARTS   AGE
prometheus-77b766c8cf-5lfcj   1/1     Running   0          2d19h
redis-69987696df-s4drs        2/2     Running   0          33s

在prometheus-cm.yaml添加配置

- job_name: 'redis'static_configs:- targets: ['redis:9121']
[root@k8s-node1 prometheus]# kubectl apply -f prometheus-cm.yaml
configmap/prometheus-config configured
[root@k8s-node1 prometheus]# kubectl get services -n kube-ops
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
prometheus   NodePort    10.101.72.224   <none>        9090:31343/TCP      2d19h
redis        ClusterIP   10.107.28.135   <none>        6379/TCP,9121/TCP   3m46s
[root@k8s-node1 prometheus]# curl -X POST "http://10.101.72.224:9090/-/reload"

访问http://192.168.100.87:31343/targets

k8s学习(二十四) 使用prometheus监控kubernetes集群应用相关推荐

  1. 使用Prometheus监控kubernetes集群

    一键安装(网络可访问quay.io): kubectl apply --filename https://raw.githubusercontent.com/giantswarm/kubernetes ...

  2. Prometheus-使用Prometheus监控Kubernetes集群

      Prometheus是一个集数据收集存储.数据查询和数据图表显示于一身的开源监控组件.本文主要讲解如何搭建Prometheus,并使用它监控Kubernetes集群. 准备工作 Kubernete ...

  3. 巧用 Prometheus 监控 Kubernetes 集群所有组件的证书

    KubeSphere 虽然提供了运维友好的向导式操作界面,简化了 Kubernetes 的运维操作,但它还是建立在底层 Kubernetes 之上的,Kubernetes 默认的证书有效期都是一年,即 ...

  4. k8s学习(2)- 虚拟机搭建搭建Kubernetes集群(1.24.2)

    虚拟机搭建搭建Kubernetes集群 环境 规划 虚拟机搭建 配置网络 解决和主机复制粘贴的问题 使用MobaXterm连接虚拟机 安装vmware tools(建议使用MobaXterm) 配置y ...

  5. OpenCV学习(二十四 ):角点检测(Corner Detection):cornerHarris(),goodFeatureToTrack()

    OpenCV学习(二十四 ):角点检测(Corner Detection):cornerHarris(),goodFeatureToTrack() 参考博客: Harris角点检测原理详解 Harri ...

  6. Web基础配置篇(十四): Kafka单机、集群的安装配置及使用

    Web基础配置篇(十四): Kafka单机.集群的安装配置及使用 一.概述 Apache Kafka是一个分布式发布 - 订阅消息系统和一个强大的队列,可以处理大量的数据,并使您能够将消息从一个端点传 ...

  7. 三种监控 Kubernetes 集群证书过期方案

    公众号关注 「奇妙的 Linux 世界」 设为「星标」,每天带你玩转 Linux ! 前言 Kubernetes 中大量用到了证书, 比如 ca证书.以及 kubelet.apiserver.prox ...

  8. 容器集群k8s从入门到精通实战第一天 kubernetes集群简介及其实例

    第一章 kubernetes介绍 本章节主要介绍应用程序在服务器上部署方式演变以及kubernetes的概念.组件和工作原理. 应用部署方式演变 在部署应用程序的方式上,主要经历了三个时代: 传统部署 ...

  9. k8s.5-使用RKE构建企业生产级Kubernetes集群

    使用RKE构建企业生产级Kubernetes集群 一.RKE工具介绍 RKE是一款经过CNCF认证的开源Kubernetes发行版,可以在Docker容器内运行. 它通过删除大部分主机依赖项,并为部署 ...

最新文章

  1. nginx在linux下安装,Nginx在linux下安装及简单命令
  2. Android热补丁技术—dexposed原理简析(手机淘宝采用方案)
  3. Java中的String、StringBuilder、StringBuffer
  4. 动态规划 dp01 西瓜分堆问题 c代码
  5. 实战SSM_O2O商铺_24【商铺列表】View层开发
  6. peripheralStateNotificationCB
  7. 百度爬虫页面自动繁殖程序+教程自动SEO优化
  8. 引用 DetachedCriteria
  9. nginx之206异常
  10. 如何使用 Siri 拨打电话并使用电话功能?
  11. 百度如何使用Go语言重构日请求量千亿级别的系统?
  12. 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。
  13. jmeter html插件,Jmeter最常见的几个插件(一)
  14. android刷成苹果手机版下载地址,安卓怎么刷苹果系统 安卓变苹果系统方法教程...
  15. 实时采集Canal快速入门
  16. 无线WIFI I/O控制器技术分享
  17. 基于 Django 的图书馆借阅系统
  18. springboot配置logback
  19. 格式化代码_格式化代码是什么意思​
  20. 论文笔记:Reasoning about Entailment with Neural Attention

热门文章

  1. js数字金额滚动动画(vue)
  2. linux 同步套件,为Linux安装套件强化系统安全
  3. Graph Neural Networks with Generated Parameters for Relation Extraction
  4. Linux route命令
  5. Muli3D 6 Struct m3dtriangleinfo 的属性 fZDdx,fZDdy 的推导
  6. 【Leetcode】644. Maximum Average Subarray II
  7. 《计算机网络面试题目总结》
  8. 远程调用中间件(RPC)
  9. BCB(C++ Builder)创建动态库(DLL,接口导出和调用),动态加载DLL
  10. TM500使用配置总结