kubernete部署prometheus监控sring-boot程序

这篇具有很好参考价值的文章主要介绍了kubernete部署prometheus监控sring-boot程序。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

1、kubernete集群环境以及prometheus基础环境

2、kubernetes监控集群内部的spring-boot程序

2.1、application.yml系统配置,endpoints相关设置

2.2、引入监控的相关依赖文件  pom.xml ,主要是spring-boot-starter-actuator和micrometer-registry-prometheus

2.3、Dockerfile构建基础镜像 

2.4、k8s环境部署spring-boot-.app.yaml

2.5、k8s部署spring-boot-app的servicemonitor

2.6、kubesphere上未安装grafana,手动部署

3、kubernetes监控集群外部的程序

3.1、准备部署文件


1、kubernete集群环境以及prometheus基础环境

kubernete部署prometheus监控sring-boot程序,prometheus

2、kubernetes监控集群内部的spring-boot程序

效果图

使用Spring Boot2.1监控系统的相关信息,grafana进行数据展示。

kubernete部署prometheus监控sring-boot程序,prometheus

Prmetheus获取/actuator/prometheus接口的数据,target进行展示

kubernete部署prometheus监控sring-boot程序,prometheusk8s部署spring-boot成功,通过swagger3进行测试访问

kubernete部署prometheus监控sring-boot程序,prometheus pod容器进行端口的映射

kubernete部署prometheus监控sring-boot程序,prometheus

进入容器内部,访问/actuator/prometheus地址 kubernete部署prometheus监控sring-boot程序,prometheus

2.1、application.yml系统配置,endpoints相关设置

server:
  port: 8080
  tomcat:
    max-http-form-post-size: 200MB
springfox:
  documentation:
    swagger-ui:
      enabled: true
spring:
  redis:
    host: redis.apisix.svc.cluster.local
    port: 6379
    database: 0
    lettuce:
      pool:
        max-active: 8
        max-wait: -1ms
        max-idle: 8
        min-idle: 0
        time-between-eviction-runs: 6s
      shutdown-timeout: 1000ms
management:
  endpoints:
    web:
      exposure:
        include: '*'
        #include:
          #- 'prometheus'
          #- 'health'
          #- 'info'
    jmx:
      exposure:
        include: '*'
    enabled-by-default: true
  endpoint:
    metrics:
      enabled: true
    beans:
      cache:
        time-to-live: 10s
    shutdown:
      enabled: true
  metrics:
    export:
      prometheus:
        enabled: true
    tags:
      application: spring-boot-app
  health:
    jms:
      enabled: true
  server:
    base-path: /
    port: 9091
 

2.2、引入监控的相关依赖文件  pom.xml ,主要是spring-boot-starter-actuator和micrometer-registry-prometheus

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/>
    </parent>
    <artifactId>spring-boot-app</artifactId>
    <name>spring-boot-app</name>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
    </dependencies>
</project>
 

2.3、Dockerfile构建基础镜像 

运行命令docker build -t zhxl1989/spring-boot-app:latest .

删除none镜像

docker images  | grep none | awk '{print $3}' | xargs docker rmi -f

FROM centos:7
ENV MYPATH /root
WORKDIR $MYPATH
RUN yum -y install vim git wget
RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
RUN yum clean all && yum makecache && yum update -y &&  yum -y install gcc gcc-c++ kernel-devel yum-utils device-mapper-persistent-data lvm2 tcpdump
RUN yum -y install net-tools
RUN yum update -y && yum install -y java-1.8.0-openjdk
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone
RUN yum install libpcap libpcap-devel -y
RUN yum -y install gcc gcc-c++ automake make pam-devel openldap-devel cyrus-sasl-devel openssl-devel wget telnet net-tools
VOLUME /tmp
WORKDIR /home/spring-boot-app/
COPY /target/lib /home/spring-boot-app/lib
COPY /target/config /home/spring-boot-app/config
COPY /target/spring-boot-app.jar /home/spring-boot-app/spring-boot-app.jar
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
EXPOSE 8080
EXPOSE 9091
...

省略
 

2.4、k8s环境部署spring-boot-.app.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-boot-app
  namespace: apisix
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spring-boot-app
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
  template:
    metadata:
      labels:
        app: spring-boot-app
        release: default
    spec:
      restartPolicy: Always
      containers:
        - name: spring-boot-app
          image: zhxl1989/spring-boot-app:latest
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
            - name: actuator
              containerPort: 9091
            - name: debug
              containerPort: 5555
          volumeMounts:
            - mountPath: /etc/localtime
              name: volume-localtime
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ''
          name: volume-localtime

---

apiVersion: v1
kind: Service
metadata:
  name: spring-boot-app
  namespace: apisix
  labels:
    app: spring-boot-app
spec:
  #type: ClusterIP
  type: NodePort
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
      nodePort: 30153
    - name: actuator
      port: 9091
      protocol: TCP
      targetPort: 9091
      nodePort: 30152
    - name: debug
      port: 5555
      protocol: TCP
      targetPort: 5555
      nodePort: 30151
  selector:
    app: spring-boot-app

2.5、k8s部署spring-boot-app的servicemonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: spring-boot-app
  namespace: demo
  #service和ServiceMonitor开始配置后,的Service Discovery有数据,但是状态UP一直为0
  #target一直找不到数据
  #label下写成k8s-app,Service Discovery有数据,Target无数据,不知道为什么
  #改成app出现正常了
  #ServiceMonitor使用的namespace一定要存在,和service的namespace可以不一样
  labels:
    app: spring-boot-app
spec:
  endpoints:
    - interval: 15s
      scheme: http
      path: /actuator/prometheus
      port: actuator
      honorLabels: true
  jobLabel: app
  namespaceSelector:
    matchNames:
      - apisix
  selector:
    matchLabels:
      app: spring-boot-app 

2.6、kubesphere上未安装grafana,手动部署

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-pvc
  namespace: apisix
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: apisix
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      securityContext:
        fsGroup: 472
        supplementalGroups:
          - 0
      containers:
        - name: grafana
          image: grafana/grafana:9.1.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
              name: http-grafana
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /robots.txt
              port: 3000
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 2
          livenessProbe:
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 3000
            timeoutSeconds: 1
          resources:
            requests:
              cpu: 250m
              memory: 750Mi
          volumeMounts:
            - mountPath: /var/lib/grafana
              name: grafana-pv
      volumes:
        - name: grafana-pv
          persistentVolumeClaim:
            claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: apisix
spec:
  ports:
    - port: 3000
      protocol: TCP
      targetPort: http-grafana
  selector:
    app: grafana
  sessionAffinity: None
  type: LoadBalancer

3、kubernetes监控集群外部的程序

3.1、准备部署文件

k8s-gitlab-ci-demo-deplyment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8s-gitlab-ci-demo
  namespace: demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k8s-gitlab-ci-demo
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
  template:
    metadata:
      labels:
        app: k8s-gitlab-ci-demo
        release: default
    spec:
      restartPolicy: Always
      containers:
        - name: k8s-gitlab-ci-demo
          image: zhxl1989/k8s-gitlab-ci-demo:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8089
              name: http
          resources:
            limits:
              cpu: '1'
              memory: 2Gi
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - mountPath: /etc/localtime
              name: volume-localtime
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ''
          name: volume-localtime

k8s-gitlab-ci-deno-service.yaml ,service中添加kind: Endpoints,指定宿主机的ip端口信息,在k8s集群外面再启动一个java进程

apiVersion: v1
kind: Service
metadata:
  labels:
    app: k8s-gitlab-ci-demo
  name: k8s-gitlab-ci-demo
  namespace: demo
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 8089
      protocol: TCP
      targetPort: 8089
---
apiVersion: v1
kind: Endpoints
metadata:
  labels:
    app: k8s-gitlab-ci-demo
  name: k8s-gitlab-ci-demo
  namespace: demo
subsets:
  - addresses:
      - ip: 10.10.10.99
    ports:
      - name: http
        port: 8089
        protocol: TCP

在10.10.10.99上通过java -jar启动程序

kubernete部署prometheus监控sring-boot程序,prometheus

 kubernete部署prometheus监控sring-boot程序,prometheus文章来源地址https://www.toymoban.com/news/detail-524290.html

到了这里,关于kubernete部署prometheus监控sring-boot程序的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Prometheus+Grafana(外)监控Kubernetes(K8s)集群(基于containerd)

    1、k8s环境 版本 v1.26.5 二进制安装Kubernetes(K8s)集群(基于containerd)—从零安装教程(带证书) 主机名 IP 系统版本 安装服务 master01 10.10.10.21 rhel7.5 nginx、etcd、api-server、scheduler、controller-manager、kubelet、proxy master02 10.10.10.22 rhel7.5 nginx、etcd、api-server、scheduler、controller-manager、kubel

    2024年02月16日
    浏览(36)
  • kubernetes部署prometheus

    Prometheus是一款由SoundCloud开发的开源监控系统,它提供了实时监测和报警功能。它的优点包括: Prometheus的缺点包括: 使用kubernetes来部署prometheus服务,prometheus数据持久化到NFS。亲测可用 clusterRole.yaml serviceaccount.yaml configmap里面的配置不需要的可以直接删除 configmap.yaml pvc.yam

    2024年02月10日
    浏览(24)
  • 云原生监控平台 Prometheus 从部署到监控

    角色 节点 IP地址 监控端 Prometheus ,Grafana,node_exporter ,Nginx 47.120.35.251 被监控端1 node_exporter 47.113.177.189 被监控端2 mysqld_exporter,node_exporter,Nginx,Nginx Exporter 47.113.146.118 2.1.1 二进制安装脚本安装Nginx 2.1.2 修改Nginx.conf 2.2.1 下载相关软件包 1.2.2 将Prometheus添加至System管理  1.2

    2024年02月11日
    浏览(38)
  • Kubernetes 笔记(17)— 系统监控、使用Metrics Server、hpa 自动伸缩 Pod 数量、Prometheus 的使用

    如果你对 Linux 系统有所了解的话,也许知道有一个命令 top 能够实时显示当前系统的 CPU 和内存利用率,它是性能分析和调优的基本工具,非常有用。 Kubernetes 也提供了类似的命令,就是 kubectl top ,不过默认情况下这个命令不会生效,必须要安装一个插件 Metrics Server 才可以。

    2024年02月01日
    浏览(28)
  • Kubernetes(k8s)监控与报警(qq邮箱+钉钉):Prometheus + Grafana + Alertmanager(超详细)

    💖The Begin💖点点关注,收藏不迷路💖 Kubernetes是一个高度动态的容器编排平台,管理着大量的容器化应用程序。 为了保证这些应用程序的稳定性和性能,我们需要实施有效的监控和警报机制。在这篇文章中,我们将介绍如何使用Prometheus和Grafana构建一个完整的Kubernetes监控与

    2024年04月11日
    浏览(49)
  • Grafana+Prometheus技术文档-进阶使用-监控spring-boot项目

    阿丹:         之前已经实现了使用Prometheus来对服务器进行了监控和仪表盘的创建,现在就需要对这些监控方法使用在spring-boot中去。         1、集成Actuator         2、加入Prometheus的依赖         3、配置开放端口、以及开放监控         4、配置Prometheus中的配置      

    2024年02月13日
    浏览(30)
  • Spring Boot进阶(94):从入门到精通:Spring Boot和Prometheus监控系统的完美结合

      随着云原生技术的发展,监控和度量也成为了不可或缺的一部分。Prometheus 是一款最近比较流行的开源时间序列数据库,同时也是一种监控方案。它具有极其灵活的查询语言、自身的数据采集和存储机制以及易于集成的特点。而 Spring Boot 是一款快速构建应用的框架,其提

    2024年02月08日
    浏览(31)
  • Kubernetes部署和使用Prometheus(图片待补)

    默认已安装kuberneter kubernetes1.25 kube-prometheus release-0.12 这里使用的是Kube-Prometheus Prometheus Server :抓取和存储时间序列数据,同时提供数据的查询和告警策略的配置管理 Alertmanager :Prometheus Server 会将告警发送给 Alertmanager,Alertmanager 根据路由配置,将告警信息发送给指定的或组

    2024年02月07日
    浏览(40)
  • Prometheus + grafana 的监控平台部署

    vim /opt/module/prometheus-2.44.0/prometheus.yml 命令 修改配置文件 命令 分发 /opt/module/node_exporter-1.6.0 目录到需要监控的节点 使用systemctl 管理node_exporter服务 分发到各个节点,并且启动服务 使用systemctl管理 kafka_exporter 服务 命令 使用systemctl 管理grafana 服务 命令 1.7.1 导入 grafana Dashboa

    2024年02月09日
    浏览(33)
  • 云原生监控平台 Prometheus 的相关概念及部署

          Prometheus 是一个开源的系统监控和报警系统,在 2012 年由 SoundCloud 公司创建,并于 2015 年正式发布。2016 年,Prometheus 正式加入 CNCF (Cloud Native Computing Foundation),成为继kubernetes之后第二个在CNCF托管的项目, 现已广泛用于在容器和微服务领域中得到了广泛的应用,当然不仅

    2024年02月10日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包